﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

namespace H2.NET.Web.Pages
{
    public partial class PCMD : TaskPage, ITempSave
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }

        }
        #endregion

        #region 事件 Page Load
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = "注意：表单正在被其他同事处理，拒绝提交表单！";
                INFO.Visible = IsOverFlow;

                LoadData(string.Empty);
            }
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            SaveData(true);
        }

        protected void Save_Click(object sender, EventArgs e)
        {
            SaveData(false);
        }


        /// <summary>
        /// 当division是K1的时候，将K1的sheet数和原有的数字相加
        /// </summary>
        /// <returns></returns>
        private int CalculateK1Count()
        {
            int k1Count = 0;
            foreach (cmd_ShipTo s in ShipTo1.ShipTos)
            {
                if (s.ST_Division.Equals("k1", StringComparison.InvariantCultureIgnoreCase))
                    k1Count++;
            }
            return k1Count;
        }

        #endregion

        #region 事件 Actions
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();
            if (Actions.SelectedValue == "1")
            {
                BA_Existed_Sold_To_Code.Visible = false;
                BA_Existed_Sold_To_Code_L.Visible = false;

                SA_No_Trans_L.Visible = false;
                SA_No_Trans.Visible = false;

                NA_Existed_Code.Visible = false;
                NA_Existed_Code_L.Visible = false;
                BA_Existed_Sold_To_Code_2.Text = "";


            }
            else
            {
                BA_Existed_Sold_To_Code.Visible = true;
                BA_Existed_Sold_To_Code_L.Visible = true;
                BA_Existed_Sold_To_Code_2.Text = BA_Existed_Sold_To_Code.Text;
                NA_Existed_Code.Visible = true;
                NA_Existed_Code_L.Visible = true;
            }

            if (Actions.SelectedValue == "4")
            {
                SA_No_Trans_L.Visible = true;
                SA_No_Trans.Visible = true;
            }
            else
            {
                SA_No_Trans_L.Visible = false;
                SA_No_Trans.Visible = false;
            }
            if (Keys.Items[1].Selected && Actions.SelectedValue == "1" && (!Keys.Items[0].Selected))
            {
                SetForeColor(Color.Blue, ShipTo1.ST_Sold_To_No_L);
                SetForeColor(Color.Black, ShipTo1.ST_Sold_To_Name_L);
            }
            //if (Actions.SelectedValue != "1")
            //{
            //    ShipTo1.ST_Total_ST_L.Visible = false;
            //    ShipTo1.ST_Total_ST.Visible = false;
            //    ShipTo1.ST_Des_Total.Visible = false;
            //}
            //else
            //{
            //    ShipTo1.ST_Total_ST_L.Visible = true;
            //    ShipTo1.ST_Total_ST.Visible = true;
            //    ShipTo1.ST_Des_Total.Visible = true;
            //}
            if (Keys.Items[1].Selected && !Keys.Items[0].Selected)
            {
                ShipTo1.Add.Visible = false;
            }
            else
            {
                ShipTo1.Add.Visible = true;
            }
            if (Keys.Items[1].Selected && Keys.Items[0].Selected && Actions.SelectedValue == "1")
            {
                ShipTo1.ST_Sold_To_No.Enabled = false;
            }

            else
            {
                ShipTo1.ST_Sold_To_No.Enabled = true;
            }

            if (Keys.Items[1].Selected && !Keys.Items[0].Selected && Actions.SelectedValue == "1")
            {
                ShipTo1.ST_Total_ST.Visible = true;
                ShipTo1.ST_Total_ST_L.Visible = true;
                ShipTo1.ST_Des_Total.Visible = true;
            }
            else
            {
                ShipTo1.ST_Total_ST.Visible = false;
                ShipTo1.ST_Total_ST_L.Visible = false;
                ShipTo1.ST_Des_Total.Visible = false;
            }



        }
        #endregion

        #region 事件 Tabs切换
        protected void MM_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P1, P2, P3);
            SoldTo.CssClass = "tabs1";
            ShipTo.CssClass = "tabs1";
            Hierarchy.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "SoldTo":
                    SoldTo.CssClass = "tabs2";
                    P1.Visible = true;
                    break;
                case "ShipTo":
                    ShipTo.CssClass = "tabs2";
                    P2.Visible = true;
                    break;
                case "Hierarchy":
                    Hierarchy.CssClass = "tabs2";
                    P3.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 事件 Tabs 选择
        protected void Key_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!Keys.Items[0].Selected && !Keys.Items[1].Selected && !Keys.Items[2].Selected)
            {
                if (SoldTo.CssClass == "tabs2")
                {
                    Keys.Items[0].Selected = true;
                }
                else if (ShipTo.CssClass == "tabs2")
                {
                    Keys.Items[1].Selected = true;
                }
                else
                {
                    Keys.Items[2].Selected = true;
                }

                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
            }

            InitTabs();
        }
        #endregion

        #region 事件 Customer Name in ZH
        protected void BA_Customer_Name_In_ZH_TextChanged(object sender, EventArgs e)
        {
            BA_Customer_Name_In_ZH_1.Text = BA_Customer_Name_In_ZH.Text;
            BA_Search_Term.Text = BA_Customer_Name_In_ZH.Text;
            if (Keys.Items[0].Selected && Keys.Items[1].Selected && Actions.SelectedValue == "1")
            {
                ShipTo1.ST_Sold_To_Name.Text = BA_Customer_Name_In_ZH.Text;
                ShipTo1.ST_Sold_To_Name_2.Text = BA_Customer_Name_In_ZH.Text;
            }
        }
        #endregion

        #region 事件 对帐单联系人和电话
        protected void BA_Existed_Dunn_Recipient_Contact_Preson_TextChanged(object sender, EventArgs e)
        {
            if (BA_Existed_Dunn_Recipient_Contact_Preson.Text != "")
            {
                FI_Customer_User.Text = BA_Existed_Dunn_Recipient_Contact_Preson.Text;

            }
            else
            {
                FI_Customer_User.Text = "";
            }
        }


        protected void BA_Existed_Dunn_Recipient_Tel_TextChanged(object sender, EventArgs e)
        {
            if (BA_Existed_Dunn_Recipient_Tel.Text != "")
            {
                FI_Act_Clk_Tel_NO.Text = BA_Existed_Dunn_Recipient_Tel.Text;
            }
            else
            {
                FI_Act_Clk_Tel_NO.Text = "";
            }
        }
        #endregion

        #region 事件 Existed Code
        protected void BA_Existed_Bill_To_Code_TextChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue != "1")
            {
                if (BA_Existed_Bill_To_Code.Text != BA_Existed_Sold_To_Code.Text)
                {
                    BA_Existed_Sold_To_Code_3.Text = "";
                }
                else
                {
                    BA_Existed_Sold_To_Code_3.Text = "请删除原bill to，并新建一个bill to";
                }
            }
        }

        protected void BA_Existed_Dunn_Recipient_Code_TextChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue != "1")
            {
                if (BA_Existed_Dunn_Recipient_Code.Text != BA_Existed_Sold_To_Code.Text)
                {
                    BA_Existed_Dunn_Recipient_Code2.Text = "";
                }
                else
                {
                    BA_Existed_Dunn_Recipient_Code2.Text = "请删除原对帐单code，并新建一个对帐单code";
                }
            }
        }

        protected void SA_Existed_Fiscal_Address_Code_1_TextChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue != "1")
            {
                if (SA_Existed_Fiscal_Address_Code_1.Text != BA_Existed_Sold_To_Code.Text)
                {
                    SA_Existed_Fiscal_Address_Code_2.Text = "";
                }
                else
                {
                    SA_Existed_Fiscal_Address_Code_2.Text = "请删除原Fiscal address code并新建一个Fiscal address code";
                }
            }
        }

        #endregion

        #region 事件 BA_Existed_Sold_To_Code
        protected void BA_Existed_Sold_To_Code_TextChanged(object sender, EventArgs e)
        {
            //SetEnable(string.IsNullOrEmpty((sender as TextBox).Text), BA_Customer_Name_In_ZH, BA_Customer_Name_In_ZH_1, BA_Search_Term, BA_Sales_Office, BA_Region, BA_City_Code);
            IList<m_Customer> cc1 = (m_Customer.customerCode == (sender as TextBox).Text).List<m_Customer>();
            m_Customer cc = (m_Customer.customerCode == (sender as TextBox).Text).ListFirst<m_Customer>();
            //if (cc1.Count == 2)
            //{
            //    SA_Customer_Division_K1.Checked = true;
            //    SA_Customer_Division_K2.Checked = true;
            //}
            //else
            //{
            //    SA_Customer_Division_K1.Checked = false;
            //    SA_Customer_Division_K2.Checked = false;
            //}
            if (cc != null)
            {
                BA_Customer_Name_In_ZH.Text = cc.CustomerName;
                BA_Customer_Name_In_ZH_1.Text = cc.CustomerName;
                BA_Search_Term.Text = cc.ShortName;
                //if (cc.Division == "K2" && cc.Division == "K1")
                //{
                //    SA_Customer_Division_K1.Checked = true;
                //    SA_Customer_Division_K2.Checked = true;
                //}

                //if (cc.Division == "K1")
                //{
                //    SA_Customer_Division_K1.Checked = true;
                //}

                //if (cc.Division == "K2")
                //{
                //    SA_Customer_Division_K2.Checked = true;
                //}

                //if (cc.Division == "K3")
                //{
                //    SA_Customer_Division_K3.Checked = true;
                //}

                foreach (ListItem li in BA_Sales_Office.Items)
                {
                    if (li.Value.IndexOf(cc.SalesOffice) != -1)
                    {
                        BA_Sales_Office.SelectedValue = li.Value;
                        BA_Sales_Office_SelectedIndexChanged1(null, e);
                        break;
                    }
                }

                foreach (ListItem li in BA_Region.Items)
                {
                    if (li.Value.IndexOf(cc.RegionID) != -1)
                    {
                        BA_Region.SelectedValue = li.Value;
                        BA_Region_SelectedIndexChanged(null, e);
                        break;
                    }
                }

                foreach (ListItem li in BA_City_Code.Items)
                {
                    if (li.Value.IndexOf(cc.CityID) != -1)
                    {
                        BA_City_Code.SelectedValue = li.Value;
                        BA_County_Code_TextChanged(null, e);
                        break;
                    }
                }
            }

            if (Actions.SelectedValue == "1")
            {
                BA_Existed_Sold_To_Code.Visible = false;
                BA_Existed_Sold_To_Code_L.Visible = false;
                BA_Existed_Sold_To_Code_2.Text = "";

                SA_No_Trans_L.Visible = false;
                SA_No_Trans.Visible = false;

                NA_Existed_Code.Visible = false;
                NA_Existed_Code_L.Visible = false;
            }
            else
            {
                BA_Existed_Sold_To_Code.Visible = true;
                BA_Existed_Sold_To_Code_L.Visible = true;
                BA_Existed_Sold_To_Code_2.Text = BA_Existed_Sold_To_Code.Text;

                NA_Existed_Code.Visible = true;
                NA_Existed_Code_L.Visible = true;
            }
            if (Actions.SelectedValue == "4")
            {
                SA_No_Trans_L.Visible = true;
                SA_No_Trans.Visible = true;
            }
            else
            {
                SA_No_Trans_L.Visible = false;
                SA_No_Trans.Visible = false;
            }

        }
        #endregion

        #region 事件 Emloyee and code必填/河南百安居
        protected void SA_Sales_Employee_TextChanged(object sender, EventArgs e)
        {
            string id = (sender as Anthem.TextBox).ID;
            if (id == "BA_Sales_Employee_K1_Employee_Code" || id == "BA_Sales_Employee_K2_Employee_Code" || id == "BA_Sales_Employee_K3_Employee_Code")
            {
                SA_Sales_Employee_Code.Text = BA_Sales_Employee_K1.Text + "/" + BA_Sales_Employee_K2.Text + "/" + BA_Sales_Employee_K3.Text;
                return;
            }

            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K1.Text != "")
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K1_Employee_Code_L, SA_Customer_Division_K1_L, SA_Attributes_1_L, SA_Attributes_2_L, SA_Attributes_7_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K1_Employee_Code_L, SA_Customer_Division_K1_L, SA_Attributes_1_L, SA_Attributes_2_L, SA_Attributes_7_L);
            }

            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K2.Text != "")
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K2_Employee_Code_L, SA_Customer_Division_K2_L, SA_Attributes_3_L, SA_Attributes_4_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K2_Employee_Code_L, SA_Customer_Division_K2_L, SA_Attributes_3_L, SA_Attributes_4_L);
            }

            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K3.Text != "")
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K3_Employee_Code_L, SA_Customer_Division_K3_L, SA_Attributes_1_L, SA_Attributes_2_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K3_Employee_Code_L, SA_Customer_Division_K3_L, SA_Attributes_1_L, SA_Attributes_2_L);
            }

            #region 河南百安居
            if (BA_Sales_Employee_K3.Text != "" && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }
            else if (SA_Customer_Division_K3.Checked && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }

            else
            {
                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Transportation_Zone.Text = BC.Transportation_Zone;
                    BA_Project_City.Text = BC.Project_City;
                }
            }

            switch (id)
            {
                case "BA_Sales_Employee_K1":
                    {
                        if (BA_Sales_Employee_K1.Text != "")
                        {
                            m_Employee_Code me = (m_Employee_Code.persNo == (sender as TextBox).Text).ListFirst<m_Employee_Code>();
                            if (me != null)
                            {
                                BA_Sales_Employee_K1_Employee_Code.Text = me.Employee;
                            }
                        }
                        else
                        {
                            BA_Sales_Employee_K1_Employee_Code.Text = "";
                        }

                    }
                    break;
                case "BA_Sales_Employee_K2":
                    {
                        if (BA_Sales_Employee_K2.Text != "")
                        {
                            m_Employee_Code me2 = (m_Employee_Code.persNo == (sender as TextBox).Text).ListFirst<m_Employee_Code>();
                            if (me2 != null)
                            {
                                BA_Sales_Employee_K2_Employee_Code.Text = me2.Employee;
                            }
                        }
                        else
                        {
                            BA_Sales_Employee_K2_Employee_Code.Text = "";
                        }
                    }
                    break;
                case "BA_Sales_Employee_K3":
                    {

                        if (BA_Sales_Employee_K3.Text != "")
                        {
                            m_Employee_Code me3 = (m_Employee_Code.persNo == (sender as TextBox).Text).ListFirst<m_Employee_Code>();
                            if (me3 != null)
                            {
                                BA_Sales_Employee_K3_Employee_Code.Text = me3.Employee;
                            }
                        }
                        else
                        {
                            BA_Sales_Employee_K3_Employee_Code.Text = "";
                        }
                    }
                    break;
            }

            #endregion

            SA_Sales_Employee.Text = BA_Sales_Employee_K1_Employee_Code.Text + "/" + BA_Sales_Employee_K2_Employee_Code.Text + "/" + BA_Sales_Employee_K3_Employee_Code.Text;
            SA_Sales_Employee_Code.Text = BA_Sales_Employee_K1.Text + "/" + BA_Sales_Employee_K2.Text + "/" + BA_Sales_Employee_K3.Text;

        }

        #endregion

        #region 选中事件 Sales Office-region
        protected void BA_Sales_Office_SelectedIndexChanged1(object sender, EventArgs e)
        {
            SA_Sales_Office.Text = BA_Sales_Office.SelectedValue;
            FI_Account_Clerk.Text = "";
            BA_City_Code.Items.Clear();
            BA_County_Code.Text = "";
            BA_Transportation_Zone.Text = "";
            BA_Project_City.Text = "";
            SA_Attributes_7.Items.Clear();
            SA_Attributes_8.Text = "";
            BA_Region.Items.Clear();
            BA_Region.Items.Add(new ListItem("", ""));
            IList<m_Sales_Office> brs = (m_Sales_Office.status == 1 & (m_Sales_Office.sales_Office == BA_Sales_Office.SelectedValue
             | m_Sales_Office.sales_Office == "")).List<m_Sales_Office>();
            foreach (m_Sales_Office BR in brs)
            {
                if (BA_Region.Items.FindByValue(BR.Region_Code_Name) == null)
                {
                    BA_Region.Items.Add(new ListItem(BR.Region_Code_Name, BR.Region_Code_Name));
                }

            }
            if (SA_Sales_Office.Text != "")
            {
                FI_Account_Clerk.Text = "0" + (BA_Sales_Office.Text.Length > 3 ? BA_Sales_Office.Text.Substring(2, 1) : BA_Sales_Office.Text);
                //ShipTo1.ST_Sales_Office.Text = BA_Sales_Office.Text;
                //ShipTo1.ST_Region.Text = BA_Region.Text;
                //ShipTo1.ST_City_Code.Text = BA_City_Code.Text;
                //ShipTo1.ST_County.Text=BA_County_Code.Text;
                //ShipTo1.ST_Transportation_Zone.Text = BA_Transportation_Zone.Text;
            }
            else
            {
                FI_Account_Clerk.Text = "";
                //ShipTo1.ST_Sales_Office.Text = "";
                //ShipTo1.ST_Region.Text = "";
                //ShipTo1.ST_City_Code.Text = "";
                //ShipTo1.ST_County.Text = "";
                //ShipTo1.ST_Transportation_Zone.Text = "";
            }

            if (Actions.SelectedValue == "1" && BA_Sales_Office.Text == "CN20_East")
            {
                SetForeColor(Color.Blue, BA_IsNeedDunn_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_IsNeedDunn_L);
            }

            if (Actions.SelectedValue == "1" && BA_Sales_Office.Text == "CN88_Staff" && ShipTo.Visible == true)
            {
                ShipTo.Visible = false;
                Keys.Items[1].Selected = false;
            }
        }
        #endregion

        #region 选中事件 Region-city/APO Customer List
        protected void BA_Region_SelectedIndexChanged(object sender, EventArgs e)
        {



            #region region-city
            BA_County_Code.Text = "";
            BA_Transportation_Zone.Text = "";
            BA_Project_City.Text = "";
            SA_Attributes_7.Items.Clear();
            SA_Attributes_8.Text = "";
            BA_City_Code.Items.Clear();
            BA_City_Code.Items.Add(new ListItem("", ""));
            IList<m_Sales_Office> bcs = (m_Sales_Office.status == 1 & (m_Sales_Office.region_Code_Name == BA_Region.SelectedValue
                | m_Sales_Office.region_Code_Name == "")).List<m_Sales_Office>();
            foreach (m_Sales_Office BC in bcs)
            {
                if (BA_City_Code.Items.FindByValue(BC.City_Code_Name) == null)
                {
                    BA_City_Code.Items.Add(new ListItem(BC.City_Code_Name, BC.City_Code_Name));

                }
            }
            //if (BA_Region.Text != "")
            //{
            //ShipTo1.ST_Region.Text = BA_Region.Text;
            //}
            //else
            //{
            //    ShipTo1.ST_Region.Text = "";
            //}
            #endregion

            #region APO Customer (K1)
            SA_APO_Customer_Group_APO_K1.Text = "";
            if (SA_Price_Group_1.Text == "")
            {
                SA_APO_Customer_Group_APO_K1.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_1.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac)
                {

                    SA_APO_Customer_Group_APO_K1.Text = SA.APO_Customer_Description;

                }
            }
            #endregion

            #region APO Customer (K2)
            SA_APO_Customer_Group_APO_K2.Text = "";
            if (SA_Price_Group_2.Text == "")
            {
                SA_APO_Customer_Group_APO_K2.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac2 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_2.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac2)
                {

                    SA_APO_Customer_Group_APO_K2.Text = SA.APO_Customer_Description;

                }
            }
            #endregion

            #region APO Customer (K3)
            SA_APO_Customer_Group_APO_K3.Text = "";
            if (SA_Price_Group_3.Text == "")
            {
                SA_APO_Customer_Group_APO_K3.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac3 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_3.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac3)
                {

                    SA_APO_Customer_Group_APO_K3.Text = SA.APO_Customer_Description;

                }
            }
            #endregion

            SA_Attributes_9.Text = BA_Region.SelectedValue;



        }


        #endregion

        #region 文本选中事件 City-county/Transportation zone
        protected void BA_County_Code_TextChanged(object sender, EventArgs e)
        {
            //SA_Attributes_8.Text = "";



            if (BA_Sales_Employee_K3.Text != "" && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }
            else if (SA_Customer_Division_K3.Checked && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }

            else
            {
                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Transportation_Zone.Text = BC.Transportation_Zone;
                    BA_Project_City.Text = BC.Project_City;
                }
            }
            #region APO Customer-Transportation
            #region APO Customer (K1)
            SA_APO_Customer_Group_APO_K1.Text = "";
            if (SA_Price_Group_1.Text == "")
            {
                SA_APO_Customer_Group_APO_K1.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_1.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac)
                {

                    SA_APO_Customer_Group_APO_K1.Text = SA.APO_Customer_Description;

                }
            }
            #endregion

            #region APO Customer (K2)
            SA_APO_Customer_Group_APO_K2.Text = "";
            if (SA_Price_Group_2.Text == "")
            {
                SA_APO_Customer_Group_APO_K2.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac2 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_2.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac2)
                {

                    SA_APO_Customer_Group_APO_K2.Text = SA.APO_Customer_Description;

                }
            }
            #endregion

            #region APO Customer (K3)
            SA_APO_Customer_Group_APO_K3.Text = "";
            if (SA_Price_Group_3.Text == "")
            {
                SA_APO_Customer_Group_APO_K3.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac3 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_3.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac3)
                {

                    SA_APO_Customer_Group_APO_K3.Text = SA.APO_Customer_Description;

                }
            }
            #endregion
            #endregion

            SA_Attributes_8.Text = "";
            SA_Attributes_7.Items.Clear();
            SA_Attributes_7.Items.Add(new ListItem("", ""));
            IList<m_Attributes_7> bcs = (m_Attributes_7.status == 1 & (m_Attributes_7.city_Code_Name == BA_City_Code.SelectedValue
                | m_Attributes_7.city_Code_Name == "")).List<m_Attributes_7>();
            foreach (m_Attributes_7 BC in bcs)
            {
                if (SA_Attributes_7.Items.FindByValue(BC.City_Code_Name) == null)
                {
                    SA_Attributes_7.Items.Add(new ListItem(BC.Attributes7, BC.Attributes7));

                }
            }
        }
        #endregion

        #region 选中事件 BA_Hierarchy_2
        protected void BA_Hierarchy_2_SelectedIndexChanged(object sender, EventArgs e)
        {
            BA_Industry3.Text = "";
            IList<m_Hierarchy2> bh2 = (m_Hierarchy2.status == 1 & (m_Hierarchy2.sAP_Code == BA_Hierarchy_2.SelectedValue
             | m_Hierarchy2.sAP_Code == "")).List<m_Hierarchy2>();
            foreach (m_Hierarchy2 BH in bh2)
            {

                BA_Industry3.Text = BH.New_Industry_Code3;

            }

            //BA_Industry2.Text = "";
            //IList<m_Hierarchy2> bh3 = (m_Hierarchy2.status == 1 & (m_Hierarchy2.sAP_Code == BA_Hierarchy_2.SelectedValue
            // | m_Hierarchy2.sAP_Code == "")).List<m_Hierarchy2>();
            //foreach (m_Hierarchy2 BH in bh3)
            //{

            //    BA_Industry2.Text = BH.New_Industry_Code2;

            //}

            #region 河南百安居
            if (BA_Sales_Employee_K3.Text != "" && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }
            else if (SA_Customer_Division_K3.Checked && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }

            else
            {
                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Transportation_Zone.Text = BC.Transportation_Zone;
                    BA_Project_City.Text = BC.Project_City;
                }
            }
            #endregion
        }
        #endregion

        #region 选中事件 SA Region-City 城市编号
        protected void SA_Region_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_City.Items.Clear();
            SA_City.Items.Add(new ListItem("", ""));
            IList<m_Sales_Office> sci = (m_Sales_Office.status == 1 & (m_Sales_Office.region_Code_Name == SA_Region.SelectedValue
             | m_Sales_Office.region_Code_Name == "")).List<m_Sales_Office>();
            foreach (m_Sales_Office SC in sci)
            {
                if (SA_City.Items.FindByValue(SC.City_Code_Name) == null)
                {
                    SA_City.Items.Add(new ListItem(SC.City_Code_Name, SC.City_Code_Name));
                }

            }

        }
        #endregion

        #region 选中事件 Invoice Type-颜色变换-Attibutes5
        protected void SA_Invoice_Type_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && SA_Invoice_Type.Text == "V_增值税发票")
            {
                SetForeColor(Color.Blue, SA_Tel_L, SA_Tax_Code_L, SA_Bank_Name_L, SA_Account_L, SA_Street_L);

            }
            else
            {
                SetForeColor(Color.Black, SA_Tel_L, SA_Tax_Code_L, SA_Bank_Name_L, SA_Account_L, SA_Street_L);
            }

            SA_Attributes5.Items.Clear();
            SA_Attributes5.Items.Add(new ListItem("", ""));
            IList<m_Attributes_5> sas1 = (m_Attributes_5.status == 1 & (m_Attributes_5.invoice_Type == SA_Invoice_Type.SelectedValue
             | m_Attributes_5.attributes_5 == "") & (m_Attributes_5.division == SA_Invoice_Division.SelectedValue
             | m_Attributes_5.attributes_5 == "")).List<m_Attributes_5>();
            foreach (m_Attributes_5 SA in sas1)
            {
                if (SA_Attributes5.Items.FindByValue(SA.Attributes_5) == null)
                {
                    SA_Attributes5.Items.Add(new ListItem(SA.Attributes_5, SA.Attributes_5));
                }

            }
        }
        #endregion

        protected void SA_Invoice_Division_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_Attributes5.Items.Clear();
            SA_Invoice_Type.Items.Clear();
            SA_Invoice_Type.Items.Add(new ListItem("", ""));
            IList<m_Attributes_5> sas = (m_Attributes_5.status == 1 & (m_Attributes_5.division == SA_Invoice_Division.SelectedValue
             | m_Attributes_5.attributes_5 == "")).List<m_Attributes_5>();
            foreach (m_Attributes_5 SA in sas)
            {
                if (SA_Invoice_Type.Items.FindByValue(SA.Invoice_Type) == null)
                {
                    SA_Invoice_Type.Items.Add(new ListItem(SA.Invoice_Type, SA.Invoice_Type));
                }

            }

        }

        #region 事件 客户定单负责人—手机必填
        protected void BA_Contact_Person_SMS_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && BA_Contact_Person_SMS.Checked)
            {
                SetForeColor(Color.Blue, BA_Contact_Person_Mobile_Phone_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Contact_Person_Mobile_Phone_L);
            }

        }
        #endregion

        #region 事件 客户总负责人—手机必填
        protected void BA_Responsible_Man_SMS_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && BA_Responsible_Man_SMS.Checked)
            {
                SetForeColor(Color.Blue, BA_Responsible_Mobile_Phone_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Responsible_Mobile_Phone_L);
            }
        }
        #endregion

        #region 事件 K1

        #region 事件 Retail-K1—必填
        protected void SA_Customer_Division_K1_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && SA_Customer_Division_K1.Checked)
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K1_L, SA_Price_Group_1_L, SA_Attributes_1_L, SA_Attributes_2_L, SA_Attributes_7_L);

                if (BA_Sales_Office.Text != "CN88_Staff")
                {
                    ShipTo.Visible = true;
                    Keys.Items[1].Selected = SA_Customer_Division_K1.Checked;
                    InitTabs();
                }
            }
            else if (SA_Customer_Division_K1.Checked && Actions.SelectedValue != "1")
            {
                SetForeColor(Color.Blue, SA_Price_Group_1_L);
                if (BA_Sales_Office.Text != "CN88_Staff")
                {
                    ShipTo.Visible = false;
                    Keys.Items[1].Selected = false;
                }
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K1_L, SA_Price_Group_1_L, SA_Attributes_1_L, SA_Attributes_2_L, SA_Attributes_7_L);
                if (BA_Sales_Office.Text != "CN88_Staff")
                {
                    ShipTo.Visible = false;
                    Keys.Items[1].Selected = false;
                }
            }
        }
        #endregion

        #region 销售员(K1)—手机必填
        protected void BA_Sales_Employee_K1_SMS_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K1_SMS.Checked)
            {

                SetForeColor(Color.Blue, BA_Sales_Employee_K1_Mobile_Phone_L);

            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K1_Mobile_Phone_L);
            }
        }
        #endregion

        #endregion

        #region 事件 K2

        #region 事件 Retail-K2—必填
        protected void SA_Customer_Division_K2_CheckedChanged(object sender, EventArgs e)
        {
            if (SA_Customer_Division_K2.Checked && Actions.SelectedValue == "1")
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K2_L, SA_Price_Group_2_L, SA_Sales_Group_2_L, SA_Attributes_3_L, SA_Attributes_4_L);
            }

            else if (SA_Customer_Division_K2.Checked && Actions.SelectedValue != "1")
            {
                SetForeColor(Color.Blue, SA_Sales_Group_2_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K2_L, SA_Price_Group_2_L, SA_Sales_Group_2_L, SA_Attributes_3_L, SA_Attributes_4_L);
            }

        }
        #endregion

        #region 销售员(K2)—手机必填
        protected void BA_Sales_Employee_K2_SMS_CheckedChanged(object sender, EventArgs e)
        {

            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K2_SMS.Checked)
            {

                SetForeColor(Color.Blue, BA_Sales_Employee_K2_Mobile_Phone_L);

            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K2_Mobile_Phone_L);
            }
        }
        #endregion

        #endregion

        #region 事件 K3/河南百安居
        #region 事件 Retail-K3—必填
        protected void SA_Customer_Division_K3_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && SA_Customer_Division_K3.Checked)
            {
                SetForeColor(Color.Blue, BA_Sales_Employee_K3_L, SA_Price_Group_3_L, SA_Attributes_1_L, SA_Attributes_2_L);
            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K3_L, SA_Price_Group_3_L, SA_Attributes_1_L, SA_Attributes_2_L);
            }

            #region 河南百安居
            if (BA_Sales_Employee_K3.Text != "" && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }
            else if (SA_Customer_Division_K3.Checked && BA_Hierarchy_2.SelectedValue == "121842" && BA_Region.SelectedValue == "编号_180_河南")
            {

                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Project_City.Text = BC.Project_City;
                }
                BA_Transportation_Zone.Text = "CNSHDJ0000";
            }

            else
            {
                IList<m_Sales_Office> bcc = (m_Sales_Office.status == 1 & (m_Sales_Office.city_Code_Name == BA_City_Code.SelectedValue
                 | m_Sales_Office.city_Code_Name == "")).List<m_Sales_Office>();
                foreach (m_Sales_Office BC in bcc)
                {
                    BA_County_Code.Text = BC.County_Code;
                    BA_Transportation_Zone.Text = BC.Transportation_Zone;
                    BA_Project_City.Text = BC.Project_City;
                }
            }
            #endregion
        }
        #endregion

        #region 销售员(K3)—手机必填
        protected void BA_Sales_Employee_K3_SMS_CheckedChanged(object sender, EventArgs e)
        {
            if (Actions.SelectedValue == "1" && BA_Sales_Employee_K3_SMS.Checked)
            {

                SetForeColor(Color.Blue, BA_Sales_Employee_K3_Mobile_Phone_L);

            }
            else
            {
                SetForeColor(Color.Black, BA_Sales_Employee_K3_Mobile_Phone_L);
            }
        }
        #endregion


        #endregion

        #region 事件 APO Customer (K1)
        protected void SA_Price_Group_1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_APO_Customer_Group_APO_K1.Text = "";
            if (SA_Price_Group_1.Text == "")
            {
                SA_APO_Customer_Group_APO_K1.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_1.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac)
                {

                    SA_APO_Customer_Group_APO_K1.Text = SA.APO_Customer_Description;

                }
            }
            switch (SA_Price_Group_1.SelectedValue)
            {
                case "RGT-KA":
                    SA_Sales_Group_1.Text = "K01";
                    Is_K02_Null.Text = "K01";
                    SA_Delivery_Priority_1.Text = "13";
                    break;

                case "RKA-KD":
                    SA_Sales_Group_1.Text = "K03";
                    Is_K02_Null.Text = "K03";
                    SA_Delivery_Priority_1.Text = "13";
                    break;

                case "RPL-KC":
                    SA_Sales_Group_1.Text = "K02";
                    Is_K02_Null.Text = "";
                    SA_Delivery_Priority_1.Text = "13";
                    break;

                default:
                    SA_Sales_Group_1.Text = "";
                    Is_K02_Null.Text = "";
                    SA_Delivery_Priority_1.Text = "";
                    break;
            }
            if (SA_Sales_Group_2.SelectedValue == "K04" && SA_Price_Group_1.Text == "RPL-KC")
            {

                IsRSM_Ship.Text = "Ship";
            }
            else
            {
                IsRSM_Ship.Text = "";
            }
        }
        #endregion

        #region 事件 APO Customer (K2)
        protected void SA_Price_Group_2_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_APO_Customer_Group_APO_K2.Text = "";
            if (SA_Price_Group_2.Text == "")
            {
                SA_APO_Customer_Group_APO_K2.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac2 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_2.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac2)
                {

                    SA_APO_Customer_Group_APO_K2.Text = SA.APO_Customer_Description;

                }
            }

        }
        #endregion

        #region 事件 APO Customer (K3)
        protected void SA_Price_Group_3_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_APO_Customer_Group_APO_K3.Text = "";
            if (SA_Price_Group_3.Text == "")
            {
                SA_APO_Customer_Group_APO_K3.Text = "";
            }
            else
            {
                IList<m_APO_Customer_List> sac3 = (m_APO_Customer_List.status == 1 & (m_APO_Customer_List.final_Name == (BA_Region.Text + SA_Price_Group_3.Text.Substring(4, 2) + BA_Transportation_Zone.Text)
                 | m_APO_Customer_List.final_Name == "")).List<m_APO_Customer_List>();
                foreach (m_APO_Customer_List SA in sac3)
                {

                    SA_APO_Customer_Group_APO_K3.Text = SA.APO_Customer_Description;

                }
            }
            switch (SA_Price_Group_3.SelectedValue)
            {
                case "RBS-KE":
                    SA_Sales_Group_3.Text = "K05";
                    SA_Delivery_Priority_3.Text = "13";
                    break;

                case "PBS-KF":
                    SA_Sales_Group_3.Text = "K06";
                    SA_Delivery_Priority_3.Text = "13";
                    break;

                default:
                    SA_Sales_Group_3.Text = "";
                    SA_Delivery_Priority_3.Text = "";
                    break;
            }
        }
        #endregion

        #region 方法 InitTabs
        protected void InitTabs()
        {
            SoldTo.Visible = Keys.Items[0].Selected;
            ShipTo.Visible = Keys.Items[1].Selected;
            Hierarchy.Visible = Keys.Items[2].Selected;

            if ((SoldTo.CssClass == "tabs2" && Keys.Items[0].Selected)
             || (ShipTo.CssClass == "tabs2" && Keys.Items[1].Selected)
             || (Hierarchy.CssClass == "tabs2" && Keys.Items[2].Selected))
            {
                return;
            }

            SetVisible(false, P1, P2, P3);
            SoldTo.CssClass = "tabs1";
            ShipTo.CssClass = "tabs1";
            Hierarchy.CssClass = "tabs1";

            //默认第1个显示 Tabs被选中
            if (SoldTo.Visible)
            {
                SoldTo.CssClass = "tabs2";
                P1.Visible = true;
                return;
            }

            if (ShipTo.Visible)
            {
                ShipTo.CssClass = "tabs2";
                P2.Visible = true;
                if (Keys.Items[1].Selected && !Keys.Items[0].Selected)
                {
                    ShipTo1.Add.Visible = false;
                }
                return;
            }

            if (Hierarchy.Visible)
            {
                Hierarchy.CssClass = "tabs2";
                P3.Visible = true;
                return;
            }
        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {
            BA_Language.Text = "ZH Chinese";
            BA_Country.Text = "CN";
            BA_Time_Zone.Text = "UTC+8";
            SA_Sales_Org.Text = "CN88";
            SA_Distribution_Channel.Text = "10";
            SA_Partial_Delivery_Per_Item_3.Text = "A 只允许一次发货";
            SA_Max_Partial_Deliveries_1.Text = "9 允许多次发货";
            SA_Max_Partial_Deliveries_2.Text = "9 允许多次发货";
            SA_Max_Partial_Deliveries_3.Text = "1 只允许一次发货";
            SA_Switch_Off_Rounding.Checked = true;
            SA_Relevant_For_POD.Checked = true;
            //SA_Delivery_Priority.Text           = "15";
            SA_Shipping_Condition.Text = "01";
            SA_Rebate.Checked = true;
            SA_Price_Determin.Checked = true;
            SA_Acct_Assgmt_Group.Text = "01";
            SA_Tax_Classification.Text = "1";
            SA_Itcoterms.Text = "Z01";
            SA_Terms_Of_Payment.Text = "CN01 Payable immediately Due net";
            SA_Customer_Group_2.Text = "001";
            SA_Customer_Group_3.Text = "001";
            FI_Recon_Account.Text = "2211000";
            FI_Sort_Key.Text = "013";
            FI_Cash_Mgmt_Group.Text = "E1";
            FI_Dunn_Procrdure.Text = "CN00";
            FI_Payment_Method.Text = "T";
            OT_Currency.SelectedValue = "CNY";
            SetEnable(false, BA_Language, BA_Country, BA_Time_Zone, SA_Sales_Org, SA_Distribution_Channel, SA_Delivery_Priority_1, SA_Delivery_Priority_3, SA_Partial_Delivery_Per_Item_3, SA_Max_Partial_Deliveries_1, SA_Max_Partial_Deliveries_2, SA_Max_Partial_Deliveries_3, SA_Switch_Off_Rounding, SA_Relevant_For_POD, SA_Delivery_Priority, SA_Shipping_Condition, SA_Rebate, SA_Price_Determin, SA_Acct_Assgmt_Group, SA_Tax_Classification, SA_Itcoterms, SA_Terms_Of_Payment, SA_Customer_Group_2, SA_Customer_Group_3, FI_Recon_Account, FI_Sort_Key, FI_Cash_Mgmt_Group, FI_Dunn_Procrdure, FI_Payment_Method, OT_Currency);
            SetForeColor(Color.Orange, BA_Language_L, BA_Country_L, BA_Time_Zone_L, SA_Sales_Org_L, SA_Distribution_Channel_L, SA_Delivery_Priority_1_L, SA_Delivery_Priority_3_L, SA_Partial_Delivery_Per_Item_3_L, SA_Max_Partial_Deliveries_1_L, SA_Max_Partial_Deliveries_2_L, SA_Max_Partial_Deliveries_3_L, SA_Switch_Off_Rounding_L, SA_Relevant_For_POD_L, SA_Delivery_Priority_L, SA_Shipping_Condition_L, SA_Rebate_L, SA_Price_Determin_L, SA_Acct_Assgmt_Group_L, SA_Tax_Classification_L, SA_Itcoterms_L, SA_Terms_Of_Payment_L, SA_Customer_Group_2_L, SA_Customer_Group_3_L, FI_Recon_Account_L, FI_Sort_Key_L, FI_Cash_Mgmt_Group_L, FI_Dunn_Procrdure_L, FI_Payment_Method_L, OT_Currency_L);
        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                BA_Hierarchy_2.Items.Clear();
                BA_Hierarchy_2.Items.Add(new ListItem("", ""));
                IList<m_Hierarchy2> hys = (m_Hierarchy2.status == 1).List<m_Hierarchy2>();
                foreach (m_Hierarchy2 HY in hys)
                {
                    BA_Hierarchy_2.Items.Add(new ListItem(HY.SAP_Code, HY.SAP_Code));
                }

                #region Sales Office(Sold to)
                BA_Sales_Office.Items.Clear();
                BA_Sales_Office.Items.Add(new ListItem("", ""));
                IList<m_Sales_Office1> bsos = (m_Sales_Office1.status == 1).List<m_Sales_Office1>();
                foreach (m_Sales_Office1 BSO in bsos)
                {
                    BA_Sales_Office.Items.Add(new ListItem(BSO.Sales_Office1, BSO.Sales_Office1));
                }
                #endregion

                #region Industry Code
                BA_Industry.Items.Clear();
                BA_Industry.Items.Add(new ListItem("", ""));
                IList<m_Industry_Code> bis = (m_Industry_Code.status == 1).List<m_Industry_Code>();
                foreach (m_Industry_Code BI in bis)
                {
                    BA_Industry.Items.Add(new ListItem(BI.Explanation, BI.Explanation));

                }
                #endregion

                #region Industry Code1
                BA_Industry1.Items.Clear();
                BA_Industry1.Items.Add(new ListItem("", ""));
                IList<m_Industry_Code1> bis1 = (m_Industry_Code1.status == 1).List<m_Industry_Code1>();
                foreach (m_Industry_Code1 BI in bis1)
                {
                    BA_Industry1.Items.Add(new ListItem(BI.Explanation, BI.Explanation));

                }
                #endregion

                #region Attributes_1
                SA_Attributes_1.Items.Clear();
                SA_Attributes_1.Items.Add(new ListItem("", ""));
                IList<m_Attributes_1> sa1 = (m_Attributes_1.status == 1).List<m_Attributes_1>();
                foreach (m_Attributes_1 SA in sa1)
                {
                    SA_Attributes_1.Items.Add(new ListItem(SA.Channel_Segment, SA.Channel_Segment));

                }
                #endregion

                #region Attributes_2
                SA_Attributes_2.Items.Clear();
                SA_Attributes_2.Items.Add(new ListItem("", ""));
                IList<m_Attributes_2> sa2 = (m_Attributes_2.status == 1).List<m_Attributes_2>();
                foreach (m_Attributes_2 SA in sa2)
                {
                    SA_Attributes_2.Items.Add(new ListItem(SA.Brand_Segment, SA.Brand_Segment));

                }
                #endregion

                #region Attributes_3
                SA_Attributes_3.Items.Clear();
                SA_Attributes_3.Items.Add(new ListItem("", ""));
                IList<m_Attributes_3> sa3 = (m_Attributes_3.status == 1).List<m_Attributes_3>();
                foreach (m_Attributes_3 SA in sa3)
                {
                    SA_Attributes_3.Items.Add(new ListItem(SA.Market_Segment, SA.Market_Segment));

                }
                #endregion

                #region Attributes_4
                SA_Attributes_4.Items.Clear();
                SA_Attributes_4.Items.Add(new ListItem("", ""));
                IList<m_Attributes_4> sa4 = (m_Attributes_4.status == 1).List<m_Attributes_4>();
                foreach (m_Attributes_4 SA in sa4)
                {
                    SA_Attributes_4.Items.Add(new ListItem(SA.Sub_Market, SA.Sub_Market));

                }
                #endregion

                #region Attributes_6
                SA_Attributes_6.Items.Clear();
                SA_Attributes_6.Items.Add(new ListItem("", ""));
                IList<m_Attributes_6> sa6 = (m_Attributes_6.status == 1).List<m_Attributes_6>();
                foreach (m_Attributes_6 SA in sa6)
                {
                    SA_Attributes_6.Items.Add(new ListItem(SA.Attributes_6, SA.Attributes_6));

                }
                #endregion

                #region SA_Region
                SA_Region.Items.Clear();
                SA_Region.Items.Add(new ListItem("", ""));
                IList<m_Sales_Office> sr = (m_Sales_Office.status == 1).List<m_Sales_Office>();
                foreach (m_Sales_Office SR in sr)
                {
                    if (SA_Region.Items.FindByValue(SR.Region_Code_Name) == null)
                    {
                        SA_Region.Items.Add(new ListItem(SR.Region_Code_Name, SR.Region_Code_Name));
                    }
                }
                #endregion

                #region NA_Region
                NA_Region.Items.Clear();
                NA_Region.Items.Add(new ListItem("", ""));
                IList<m_Sales_Office> nr = (m_Sales_Office.status == 1).List<m_Sales_Office>();
                foreach (m_Sales_Office NR in nr)
                {
                    if (NA_Region.Items.FindByValue(NR.Region_Code_Name) == null)
                    {
                        NA_Region.Items.Add(new ListItem(NR.Region_Code_Name, NR.Region_Code_Name));
                    }
                }
                #endregion

                #region street5(Existed)
                BA_Existed_Sold_To_Code_Street5.Items.Clear();
                BA_Existed_Sold_To_Code_Street5.Items.Add(new ListItem("", ""));
                IList<m_Region_City> bes = (m_Region_City.status == 1).List<m_Region_City>();
                foreach (m_Region_City BE in bes)
                {
                    if (BA_Existed_Sold_To_Code_Street5.Items.FindByValue(BE.Region) == null)
                    {
                        BA_Existed_Sold_To_Code_Street5.Items.Add(new ListItem(BE.Region, BE.Region));
                    }
                }
                #endregion

                #region street5(Bill)
                BA_Existed_Bill_To_Code_Street5.Items.Clear();
                BA_Existed_Bill_To_Code_Street5.Items.Add(new ListItem("", ""));
                IList<m_Region_City> beb = (m_Region_City.status == 1).List<m_Region_City>();
                foreach (m_Region_City BE in beb)
                {
                    if (BA_Existed_Bill_To_Code_Street5.Items.FindByValue(BE.Region) == null)
                    {
                        BA_Existed_Bill_To_Code_Street5.Items.Add(new ListItem(BE.Region, BE.Region));
                    }
                }
                #endregion

                #region street5(Dunn)
                BA_Existed_Dunn_Recipient_Street5.Items.Clear();
                BA_Existed_Dunn_Recipient_Street5.Items.Add(new ListItem("", ""));
                IList<m_Region_City> bed = (m_Region_City.status == 1).List<m_Region_City>();
                foreach (m_Region_City BE in bed)
                {
                    if (BA_Existed_Dunn_Recipient_Street5.Items.FindByValue(BE.Region) == null)
                    {
                        BA_Existed_Dunn_Recipient_Street5.Items.Add(new ListItem(BE.Region, BE.Region));
                    }
                }
                #endregion

                #region street5(NA)
                NA_Street5.Items.Clear();
                NA_Street5.Items.Add(new ListItem("", ""));
                IList<m_Region_City> ns = (m_Region_City.status == 1).List<m_Region_City>();
                foreach (m_Region_City NS in ns)
                {
                    if (NA_Street5.Items.FindByValue(NS.Region) == null)
                    {
                        NA_Street5.Items.Add(new ListItem(NS.Region, NS.Region));
                    }
                }
                #endregion


                #region Division-Invoice
                SA_Invoice_Division.Items.Clear();
                SA_Invoice_Division.Items.Add(new ListItem("", ""));
                IList<m_Attributes_5> sits = (m_Attributes_5.status == 1).List<m_Attributes_5>();
                foreach (m_Attributes_5 SIT in sits)
                {
                    if (SA_Invoice_Division.Items.FindByValue(SIT.Division) == null)
                    {
                        SA_Invoice_Division.Items.Add(new ListItem(SIT.Division, SIT.Division));

                    }
                }
                #endregion

                #region
                SA_Account_Type.Items.Clear();
                SA_Account_Type.Items.Add(new ListItem("", ""));
                IList<m_Account_Type> sat = (m_Account_Type.status == 1).List<m_Account_Type>();
                foreach (m_Account_Type SIT in sat)
                {
                    if (SA_Account_Type.Items.FindByValue(SIT.Account_Type) == null)
                    {
                        SA_Account_Type.Items.Add(new ListItem(SIT.Account_Type, SIT.Account_Type));

                    }
                }
                #endregion
            }
        }
        #endregion

        #region 方法 DataValidation
        private List<string> DataValidation()
        {
            List<string> vald_s = new List<string>();
            List<string> vald_s_2 = new List<string>();
            List<string> vald_s_3 = new List<string>();
            List<Regular> regs = new List<Regular>();

            if (Keys.Items[2].Selected && (Keys.Items[0].Selected | Keys.Items[1].Selected)) { regs.Add(new Regular(RegularExp.NotEmpty, "", "选择了Sold To或Ship To 则不能选Hierarchy")); }

            if (BA_Sales_Office.SelectedValue != "CN88_Staff")
            {
                if ((SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K3.Checked) ||
                    (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked) ||
                (SA_Customer_Division_K1.Checked && SA_Customer_Division_K3.Checked && !SA_Customer_Division_K2.Checked) ||
                   (SA_Customer_Division_K2.Checked && SA_Customer_Division_K3.Checked && !SA_Customer_Division_K1.Checked))
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "Sold to: 一次同时只能申请一个渠道"));
                }
                //if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && SA_Sales_Group_2.SelectedValue != "KI")
                //{
                //    regs.Add(new Regular(RegularExp.NotEmpty, "", "Sold to: Sales Group选择KG或者KH，则不能同时勾选K1"));
                //}

            }

            #region Sold To
            if (Keys.Items[0].Selected && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Customer_Name_In_ZH.Text, "Sold to: 客户名称1Customer Name1 in ZH 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Business_License_No.Text, "Sold to: 注册号Business License No. 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_SoldTo_Relation.Text, "Sold to: 同一老板不同账号Relation 必填，如果没有，请填“无”"));

                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_Street5.SelectedValue, "Sold to: 客户注册地址:省 Street5 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_City.Text, "Sold to: 市 City 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_Post_Code.Text, "Sold to: 客户注册地址:邮编 Post code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Convert.ToString(SA_Customer_Division_K1.Checked) + Convert.ToString(SA_Customer_Division_K2.Checked) + Convert.ToString(SA_Customer_Division_K3.Checked), "Sold to:  1.Retail-K1 或 2.Project-K2 或 3.Modern Trade-K3至少需要填写 1 个"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K1.Text + BA_Sales_Employee_K2.Text + BA_Sales_Employee_K3.Text, "Sold to:  销售人员SAP代码(K1) 或 销售人员SAP代码(K2) 或 销售人员SAP代码(K3) 至少需要填写 1 个"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_Street.Text, "Sold to: 客户注册地址:详细地址 Street 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_Tel.Text, "Sold to: 客户注册地址:电话 Tel 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code_Contact_Preson.Text, "Sold to: 客户注册地址:联系 Contact Person 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Bill_To_Code_Street5.SelectedValue, "Sold to: 发票邮寄地址:省 Street5 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Bill_To_Code_Post_Code.Text, "Sold to: 发票邮寄地址:邮编 Post code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Bill_To_Code_Street.Text, "Sold to: 发票邮寄地址:详细地址 Street 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Bill_To_Code_Tel.Text, "Sold to: 发票邮寄地址:电话 Tel 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Bill_To_Code_Contact_Preson.Text, "Sold to: 发票邮寄地址:联系 Contact Person 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Dunn_Recipient_Street5.SelectedValue, "Sold to: 对帐单邮寄地址:省 Street5 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Dunn_Recipient_Post_Code.Text, "Sold to: 对帐单邮寄地址:邮编 Post code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Dunn_Recipient_Street.Text, "Sold to: 对帐单邮寄地址:详细地址 Street 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Dunn_Recipient_Tel.Text, "Sold to: 对帐单邮寄地址:电话 Tel 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Dunn_Recipient_Contact_Preson.Text, "Sold to: 对帐单邮寄地址:联系 Contact Person 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Office.SelectedValue, "Sold to: Sales Office区域 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Region.SelectedValue, "Sold to: Region省份编码 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_City_Code.SelectedValue, "Sold to: City Code城市名称 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Industry.SelectedValue, "Sold to: Industry 行业代码 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Industry1.SelectedValue, "Sold to: Industry1行业代码1 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Account_Type.SelectedValue, "Sold to: 账号类型 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, SA_Invoice_Division.SelectedValue, "Sold to: 财务资料中Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Invoice_Type.SelectedValue, "Sold to: 发票类型Invoice type 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes5.SelectedValue, "Sold to: 开具发票的时限 Attributes5 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, SA_Tax_Code.Text, "Sold to: 税务登记证号 Tax code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, FI_Account_Memo.Text, "Sold to: Account memo 法人姓名 必填"));

                if (BA_Sales_Office.Text == "CN20_East")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_IsNeedDunn.SelectedValue, "Sold to: 是否需要每月提供对账单 必填"));
                }




                if (SA_Invoice_Type.Text == "V_增值税发票")
                {
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_Invoice_Name.Text, "Sold to: 开票名称 Invoice Name 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_Region.SelectedValue, "Sold to: 开票省份编码 Region 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_City.SelectedValue, "Sold to: 开票客户城市 City 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_Street5.Text, "Sold to: 省 Street5 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_City2.Text, "Sold to: 市 City 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_District.Text, "Sold to: 区（县）District 必填"));
                    //regs.Add(new Regular(RegularExp.NotEmpty, SA_Street.Text, "Sold to: 详细地址 Street 必填"));

                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Street.Text, "Sold to: 发票详细地址 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Tel.Text, "Sold to: 开票电话 Tel 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Bank_Name.Text, "Sold to: 客户开户银行 Bank Name 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Account.Text, "Sold to: 客户银行帐号Bank Account 必填"));
                }

                if (BA_Contact_Person_SMS.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Contact_Person_Mobile_Phone.Text, "Sold to: 客户订单负责人 Contact Person 必填"));

                }

                if (BA_Responsible_Man_SMS.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Responsible_Mobile_Phone.Text, "Sold to: 客户总负责人 Responsible Man 必填"));

                }

                #region K1
                if (SA_Customer_Division_K1.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K1.Text, "Sold to: 销售人员SAP代码 SAP Sales Employee code 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Price_Group_1.SelectedValue, "Sold to: Price Group(K1) 必填"));
                }

                if (BA_Sales_Employee_K1.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K1_Employee_Code.Text, "Sold to: AKZO销售员姓名Sales Employee(K1) 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Customer_Division_K1.Checked ? "blank" : "", "Sold to: 1.Retail-K1 必填"));
                }

                if (SA_Customer_Division_K1.Checked || BA_Sales_Employee_K1.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_1.SelectedValue, "Sold to: Attributes1 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_2.SelectedValue, "Sold to: Attributes2 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_7.SelectedValue, "Sold to: Attributes7 必填"));
                }

                if (BA_Sales_Employee_K1_SMS.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K1_Mobile_Phone.Text, "Sold to: 手机号Mobile Phone 必填"));
                    SetForeColor(Color.Blue, BA_Sales_Employee_K1_Mobile_Phone_L);
                }
                #endregion

                #region K2
                if (SA_Customer_Division_K2.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K2.Text, "Sold to: 销售人员SAP代码SAP Sales Employee code(K2) 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Price_Group_2.SelectedValue, "Sold to: Price Group(K2) 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Sales_Group_2.SelectedValue, "Sold to: Sales Group(K2) 必填"));
                    SetForeColor(Color.Blue, BA_Sales_Employee_K2_L, SA_Sales_Group_2_L, SA_Price_Group_2_L, SA_Attributes_3_L, SA_Attributes_4_L);
                }

                if (BA_Sales_Employee_K2.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Customer_Division_K2.Checked ? "blank" : "", "Sold to: 2. Project-K2 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K2_Employee_Code.Text, "Sold to: AKZO销售员姓名Sales Employee(K2) 必填"));
                    SetForeColor(Color.Blue, SA_Customer_Division_K2_L, BA_Sales_Employee_K2_Employee_Code_L, SA_Attributes_3_L, SA_Attributes_4_L);
                }

                if (SA_Customer_Division_K2.Checked || BA_Sales_Employee_K2.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_3.SelectedValue, "Sold to: Attributes3 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_4.SelectedValue, "Sold to: Attributes4 必填"));
                }

                if (BA_Sales_Employee_K2_SMS.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K2_Mobile_Phone.Text, "Sold to: 手机号Mobile Phone 必填"));
                    SetForeColor(Color.Blue, BA_Sales_Employee_K2_Mobile_Phone_L);
                }

                #endregion

                #region K3
                if (SA_Customer_Division_K3.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K3.Text, "Sold to: 销售人员SAP代码SAP Sales Employee code(K3) 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Price_Group_3.SelectedValue, "Sold to: Price Group(K3) 必填"));
                    SetForeColor(Color.Blue, BA_Sales_Employee_K3_L, SA_Price_Group_3_L, SA_APO_Customer_Group_APO_K3_L);
                }
                if (BA_Sales_Employee_K3_SMS.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K3_Mobile_Phone.Text, "Sold to: 手机号Mobile Phone 必填"));
                    SetForeColor(Color.Blue, BA_Sales_Employee_K3_Mobile_Phone_L);
                }

                if (BA_Sales_Employee_K3.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Customer_Division_K3.Checked ? "blank" : "", "Sold to: 3.Modern Trade-K3 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Employee_K3_Employee_Code.Text, "Sold to: AKZO销售员姓名Sales Employee(K3) 必填"));
                    SetForeColor(Color.Blue, SA_Customer_Division_K3_L, BA_Sales_Employee_K3_Employee_Code_L, SA_Attributes_1_L, SA_Attributes_2_L);
                }

                if (SA_Customer_Division_K3.Checked || BA_Sales_Employee_K3.Text != "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_1.SelectedValue, "Sold to: Attributes1 必填"));
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Attributes_2.SelectedValue, "Sold to: Attributes2 必填"));
                }
                #endregion
            }

            if (Keys.Items[0].Selected && Actions.SelectedValue != "1")
            {
                //regs.Add(new Regular(RegularExp.NotEmpty, BA_Customer_Name_In_ZH.Text, "Sold to: 客户名称1(营业执照) 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code.Text, "Sold to: 原帐号号码Existed Sold-to Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, BA_Sales_Office.SelectedValue, "Sold to: 请输入正确的原帐号号码Existed Sold-to Code:"));
                if (!SA_Customer_Division_K3.Checked && !SA_Customer_Division_K1.Checked && !SA_Customer_Division_K2.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "Sold to: 请选择Customer Division客户类型 "));
                }
                if (SA_Customer_Division_K2.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Sales_Group_2.SelectedValue, "Sold to: Sales Group(K2) 必填"));
                }

                if (SA_Customer_Division_K1.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, SA_Price_Group_1.SelectedValue, "Sold to: Price Group(K1) 必填"));
                }
            }

            if (Keys.Items[0].Selected && Actions.SelectedValue == "4")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, SA_No_Trans.SelectedValue, "Sold to: 是否违反公司规定停止合作？ 必填"));
            }

            //if (Keys.Items[0].Selected && Actions.SelectedValue == "3")
            //{
            //    //regs.Add(new Regular(RegularExp.NotEmpty, BA_Customer_Name_In_ZH.Text, "Sold to: 客户名称1(营业执照) 必填"));
            //    regs.Add(new Regular(RegularExp.NotEmpty, BA_Block_Existed_Code.SelectedValue, "Sold to: 是否冻结原账号Block Existed Code 必填"));
            //}

            //if (Keys.Items[0].Selected && Actions.SelectedValue == "4")
            //{
            //    regs.Add(new Regular(RegularExp.NotEmpty, BA_Customer_Name_In_ZH.Text, "Sold to: 客户名称1(营业执照) 必填"));
            //    regs.Add(new Regular(RegularExp.NotEmpty, BA_Existed_Sold_To_Code.Text, "Sold to: 原帐号号码Existed Sold-to Code 必填"));
            //}
            if (SA_Attributes_10.Text.Length > 4)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, "", "Sold to: Attributes10 长度不能大于4位！"));
            }

            vald_s = Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>Sold To </b></font>");
            }

            #endregion

            #region Hierarchy
            regs.Clear();
            //if (NA_Customer_Division_K3.Checked && (NA_Customer_Division_K1.Checked | NA_Customer_Division_K2.Checked))
            //{
            //    regs.Add(new Regular(RegularExp.NotEmpty, "", "Hierarchy: 勾选了K1或K2 则不能勾选K3"));
            //}

            if (Keys.Items[2].Selected && Actions.SelectedValue == "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Customer_Name.Text, "Hierarchy : 客户名称Customer Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Customer_Detailed_Add.Text, "Hierarchy : 注册地址Customer Detailed Add."));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Street5.Text, "Hierarchy : 省 Street5 必填"));
                //regs.Add(new Regular(RegularExp.NotEmpty, NA_City.Text, "Hierarchy : 市 City 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Post_Code.Text, "Hierarchy : 邮编 Post code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Street.Text, "Hierarchy : 详细地址 Street 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Contact_Preson.Text, "Hierarchy : 联系人Contact Person 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Tel.Text, "Hierarchy : 电话 Tel 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!NA_Customer_Division_K1.Checked && !NA_Customer_Division_K2.Checked && !NA_Customer_Division_K3.Checked ? "" : "NotBlank"), "Hierarchy:  1.Retail-K1 或 2.Project-K2 或 3.卖场-K3至少需要填写 1 个"));
            }

            if (Keys.Items[2].Selected && Actions.SelectedValue != "1")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Customer_Name.Text, "Hierarchy : 客户名称Customer Name 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Existed_Code.Text, "Hierarchy: 原帐号号码Existed Sold Code 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, NA_Region.SelectedValue, "Hierarchy: Region省份编码 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, (!NA_Customer_Division_K1.Checked && !NA_Customer_Division_K2.Checked && !NA_Customer_Division_K3.Checked ? "" : "NotBlank"), "Hierarchy:  1.Retail-K1 或 2.Project-K2 或 3.卖场-K3至少需要填写 1 个"));

            }

            vald_s_2 = Validation(regs);
            if (vald_s_2.Count > 0)
            {
                vald_s_2.Insert(0, "<font color='#0000FF'><b>Hierarchy </b></font>");
                vald_s.AddRange(vald_s_2);
            }
            #endregion


            //if (TaskAPI.Step == "DMO Approve" & Assessment1.Assessment.Opinion == "1")
            //{
            //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_DrpPriority.SelectedValue, " Priority 必填"));
            //}



            if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            {

                if (DMO_Arrpvoe_Creation_Number.Text == "" | DMO_Arrpvoe_Creation_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Creation项必填"));
                }
                regs.Add(new Regular(RegularExp.NotEmpty, DMO_CheckList.Checked ? "blank" : "", "请注意审核事项"));

            }
            if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            {

                if (DMO_Maintain_Creation_Number.Text == "" | DMO_Maintain_Creation_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Creation项必填"));
                }

            }
            if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1" & Assessment1.Assessment.Opinion == "1")
            {
                if (DMO_Check_Creation_Number.Text == "" | DMO_Check_Creation_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Creation项必填"));
                }

            }
            if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            {
                if (DMO_Arrpvoe_Revision_Number.Text == "" | DMO_Arrpvoe_Revision_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Approve的Revision项必填"));
                }
                //if (SA2.Checked & VD_Category.SelectedValue == "1")
                //{
                //    regs.Add(new Regular(RegularExp.NotEmpty, DMO_SalesSAP_Code.Text, "Sales SAP Code 必填"));
                //}
            }
            if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            {
                if (DMO_Maintain_Revision_Number.Text == "" | DMO_Maintain_Revision_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Maintain的Revision项必填"));
                }

            }
            if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1" & Assessment1.Assessment.Opinion == "1")
            {
                if (DMO_Check_Revision_Number.Text == "" | DMO_Check_Revision_Time.Text == "")
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", " DMO Check的Revision项必填"));
                }

            }

            vald_s_3 = Validation(regs);

            if (vald_s_3.Count > 0)
            {

                vald_s.AddRange(vald_s_3);
            }

            return vald_s;
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Black, FI_Account_Clerk_L, SA_Invoice_Division_L, BA_Existed_Dunn_Recipient_Tel_L, BA_Existed_Dunn_Recipient_Contact_Preson_L, BA_Existed_Dunn_Recipient_Post_Code_L, BA_Existed_Dunn_Recipient_Street_L, SA_Account_Type_L, BA_Existed_Dunn_Recipient_Street5_L, BA_Existed_Bill_To_Code_Tel_L, BA_Existed_Bill_To_Code_Contact_Preson_L, BA_Existed_Bill_To_Code_Street_L, BA_Existed_Bill_To_Code_Post_Code_L, BA_Existed_Bill_To_Code_Street5_L, BA_Existed_Sold_To_Code_Post_Code_L, NA_Post_Code_L, BA_Customer_Name_In_ZH_L, BA_Customer_Name_In_ZH_1_L, BA_Block_Existed_Code_L, BA_Existed_Sold_To_Code_L, NA_Existed_Code_L, BA_Existed_Sold_To_Code_Street5_L, BA_Existed_Sold_To_Code_Street_L, BA_Existed_Sold_To_Code_Contact_Preson_L, BA_Existed_Sold_To_Code_Tel_L, BA_Sales_Office_L, BA_Region_L, BA_City_Code_L, BA_Industry_L, BA_Industry1_L, SA_Invoice_Type_L, SA_Attributes5_L, SA_Tax_Code_L, FI_Account_Memo_L, BA_Customer_Name_In_ZH_1_L, BA_Business_License_No_L, BA_SoldTo_Relation_L, BA_Search_Term_L, SA_Attributes_9_L, SA_Attributes_10_L, NA_Customer_Detailed_Add_L, NA_Street5_L, NA_Street_L, NA_Contact_Preson_L, NA_Tel_L, NA_Region_L);

            switch (Actions.SelectedValue)
            {
                case "1":
                    SetForeColor(Color.Blue, BA_Existed_Dunn_Recipient_Contact_Preson_L, SA_Invoice_Division_L, BA_Existed_Dunn_Recipient_Tel_L, BA_Existed_Dunn_Recipient_Street5_L, BA_Existed_Dunn_Recipient_Post_Code_L, SA_Account_Type_L, BA_Existed_Dunn_Recipient_Street_L, BA_Existed_Bill_To_Code_Tel_L, BA_Existed_Bill_To_Code_Contact_Preson_L, BA_Existed_Bill_To_Code_Street_L, BA_Existed_Bill_To_Code_Post_Code_L, BA_Existed_Bill_To_Code_Street5_L, BA_Existed_Sold_To_Code_Post_Code_L, NA_Post_Code_L, NA_Customer_Name_L, BA_Customer_Name_In_ZH_L, BA_Customer_Name_In_ZH_1_L, BA_Existed_Sold_To_Code_Street5_L, BA_Existed_Sold_To_Code_Street_L, BA_Existed_Sold_To_Code_Contact_Preson_L, BA_Existed_Sold_To_Code_Tel_L, BA_Sales_Office_L, BA_Region_L, BA_City_Code_L, BA_Industry_L, BA_Industry1_L, SA_Invoice_Type_L, SA_Attributes5_L, SA_Tax_Code_L, FI_Account_Memo_L, BA_Customer_Name_In_ZH_1_L, BA_Business_License_No_L, BA_SoldTo_Relation_L, BA_Search_Term_L, NA_Customer_Detailed_Add_L, NA_Street5_L, NA_Street_L, NA_Contact_Preson_L, NA_Tel_L, NA_Region_L);
                    break;

                case "2":
                    SetForeColor(Color.Blue, BA_Existed_Sold_To_Code_L, NA_Existed_Code_L, NA_Region_L);
                    break;

                case "3":
                    SetForeColor(Color.Blue, BA_Existed_Sold_To_Code_L, NA_Existed_Code_L, NA_Region_L);
                    break;

                case "4":
                    SetForeColor(Color.Blue, BA_Existed_Sold_To_Code_L, NA_Existed_Code_L, NA_Region_L, SA_No_Trans_L);
                    break;

                case "5":
                    SetForeColor(Color.Blue, BA_Existed_Sold_To_Code_L, NA_Existed_Code_L, NA_Region_L);
                    break;
            }

            ShipTo1.SetColor();
        }
        #endregion

        #region 方法 SetCheckList
        private Anthem.CheckBoxList setCheckList(string t, Anthem.CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                //if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                //{
                //    drpT.SelectedValue = o.ToString();
                //    return;
                //}
                // drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                // drpT.SelectedValue = o.ToString();
                //魏军为了修改下拉框的enable属性而改。

                if ((!TaskAPI.IsBeginStep && TaskAPI.Step != "CA Check") || !TaskAPI.IsAllowSubmit)
                {
                    drpT.SelectedValue = o.ToString();
                    string item = drpT.SelectedItem.Text;
                    drpT.Items.Clear();
                    drpT.Items.Add(new ListItem(item, o.ToString()));
                    drpT.SelectedValue = o.ToString();

                }
                else
                {
                    if (drpT.Items.FindByValue(o.ToString().Trim()) != null)
                    {
                        drpT.SelectedValue = o.ToString();
                        return;
                    }
                    else
                    {
                        string item = drpT.SelectedItem.Text;
                        drpT.Items.Add(new ListItem(item, o.ToString()));
                        drpT.SelectedValue = o.ToString();

                    }

                }

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion

        #region region-city(Existed)
        protected void BA_Existed_Sold_To_Code_Street5_SelectedIndexChanged(object sender, EventArgs e)
        {
            //BA_Existed_Sold_To_Code_City.Items.Clear();
            //BA_Existed_Sold_To_Code_City.Items.Add(new ListItem("", ""));
            //IList<m_Region_City> bes1 = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Sold_To_Code_Street5.SelectedValue
            //    | m_Region_City.region == "")).List<m_Region_City>();
            //foreach (m_Region_City BE in bes1)
            //{
            //    if (BA_Existed_Sold_To_Code_City.Items.FindByValue(BE.City) == null)
            //    {
            //        BA_Existed_Sold_To_Code_City.Items.Add(new ListItem(BE.City, BE.City));

            //    }
            //}

            IList<m_Region_City> mrc = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Sold_To_Code_Street5.SelectedValue
                 | m_Region_City.region == "")).List<m_Region_City>();
            foreach (m_Region_City MR in mrc)
            {
                BA_Existed_Sold_To_Code_Post_Code.Text = MR.PostCode;

            }
        }
        #endregion

        #region region-city(Bill)
        protected void BA_Existed_Bill_To_Code_Street5_SelectedIndexChanged(object sender, EventArgs e)
        {
            //BA_Existed_Bill_To_Code_City.Items.Clear();
            //BA_Existed_Bill_To_Code_City.Items.Add(new ListItem("", ""));
            //IList<m_Region_City> bes1 = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Bill_To_Code_Street5.SelectedValue
            //    | m_Region_City.region == "")).List<m_Region_City>();
            //foreach (m_Region_City BE in bes1)
            //{
            //    if (BA_Existed_Bill_To_Code_City.Items.FindByValue(BE.City) == null)
            //    {
            //        BA_Existed_Bill_To_Code_City.Items.Add(new ListItem(BE.City, BE.City));

            //    }
            //}

            IList<m_Region_City> mrc2 = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Bill_To_Code_Street5.SelectedValue
                 | m_Region_City.region == "")).List<m_Region_City>();
            foreach (m_Region_City MR in mrc2)
            {
                BA_Existed_Bill_To_Code_Post_Code.Text = MR.PostCode;

            }
        }
        #endregion

        #region region-city(Dunn)
        protected void BA_Existed_Dunn_Recipient_Street5_SelectedIndexChanged(object sender, EventArgs e)
        {
            //BA_Existed_Dunn_Recipient_City.Items.Clear();
            //BA_Existed_Dunn_Recipient_City.Items.Add(new ListItem("", ""));
            //IList<m_Region_City> bes1 = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Dunn_Recipient_Street5.SelectedValue
            //    | m_Region_City.region == "")).List<m_Region_City>();
            //foreach (m_Region_City BE in bes1)
            //{
            //    if (BA_Existed_Dunn_Recipient_City.Items.FindByValue(BE.City) == null)
            //    {
            //        BA_Existed_Dunn_Recipient_City.Items.Add(new ListItem(BE.City, BE.City));

            //    }
            //}

            IList<m_Region_City> mrc3 = (m_Region_City.status == 1 & (m_Region_City.region == BA_Existed_Dunn_Recipient_Street5.SelectedValue
                 | m_Region_City.region == "")).List<m_Region_City>();
            foreach (m_Region_City MR in mrc3)
            {
                BA_Existed_Dunn_Recipient_Post_Code.Text = MR.PostCode;

            }
        }
        #endregion

        protected void NA_Street5_SelectedIndexChanged(object sender, EventArgs e)
        {
            //NA_City.Items.Clear();
            //NA_City.Items.Add(new ListItem("", ""));
            //IList<m_Region_City> bes1 = (m_Region_City.status == 1 & (m_Region_City.region == NA_Street5.SelectedValue
            //    | m_Region_City.region == "")).List<m_Region_City>();
            //foreach (m_Region_City BE in bes1)
            //{
            //    if (NA_City.Items.FindByValue(BE.City) == null)
            //    {
            //        NA_City.Items.Add(new ListItem(BE.City, BE.City));

            //    }
            //}

            IList<m_Region_City> mrc4 = (m_Region_City.status == 1 & (m_Region_City.region == NA_Street5.SelectedValue
                 | m_Region_City.region == "")).List<m_Region_City>();
            foreach (m_Region_City MR in mrc4)
            {
                NA_Post_Code.Text = MR.PostCode;

            }
        }

        protected void NA_Region_SelectedIndexChanged(object sender, EventArgs e)
        {
            //NA_Sales_Office.Text = "";
            //IList<m_Region_SalesOffice> mrss = (m_Region_SalesOffice.status == 1 & (m_Region_SalesOffice.region == NA_Region.SelectedValue
            // | m_Region_SalesOffice.region == "")).List<m_Region_SalesOffice>();
            //foreach (m_Region_SalesOffice MR in mrss)
            //{
            //        NA_Sales_Office.Text=MR.SalesOffice;

            //}
        }

        #region 事件 NA_Existed_Code
        protected void NA_Existed_Code_TextChanged(object sender, EventArgs e)
        {
            m_Customer ncc = (m_Customer.customerCode == (sender as TextBox).Text).ListFirst<m_Customer>();
            IList<m_Customer> ncc2 = (m_Customer.customerCode == (sender as TextBox).Text).List<m_Customer>();
            IList<m_Customer> ncc3 = (m_Customer.customerCode == (sender as TextBox).Text).List<m_Customer>();
            if (ncc2.Count == 2)
            {
                NA_Customer_Division_K1.Checked = true;
                NA_Customer_Division_K2.Checked = true;
            }
            else
            {
                NA_Customer_Division_K1.Checked = false;
                NA_Customer_Division_K2.Checked = false;
            }
            if (ncc3.Count == 3)
            {
                NA_Customer_Division_K1.Checked = true;
                NA_Customer_Division_K2.Checked = true;
                NA_Customer_Division_K3.Checked = true;
            }
            else
            {
                NA_Customer_Division_K1.Checked = false;
                NA_Customer_Division_K2.Checked = false;
                NA_Customer_Division_K3.Checked = false;
            }

            if (ncc != null)
            {
                NA_Customer_Name.Text = ncc.CustomerName;

                if (ncc.Division == "K2" && ncc.Division == "K1")
                {
                    NA_Customer_Division_K1.Checked = true;
                    NA_Customer_Division_K2.Checked = true;
                }

                if (ncc.Division == "K1")
                {
                    NA_Customer_Division_K1.Checked = true;
                }

                if (ncc.Division == "K2")
                {
                    NA_Customer_Division_K2.Checked = true;
                }

                if (ncc.Division == "K3")
                {
                    NA_Customer_Division_K3.Checked = true;
                }


                foreach (ListItem li in NA_Region.Items)
                {
                    if (li.Value.IndexOf(ncc.RegionID) != -1)
                    {
                        NA_Region.SelectedValue = li.Value;
                        NA_Region_SelectedIndexChanged(null, e);
                        break;
                    }
                }

            }
        }
        #endregion

        #region 控制流程k2
        protected void SA_Sales_Group_2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (SA_Sales_Group_2.SelectedValue == "K04")
            {
                Is_Sales_Null.Text = "";
                SA_Delivery_Priority.Text = "13";
            }
            else if (SA_Sales_Group_2.SelectedValue == "K07")
            {
                Is_Sales_Null.Text = "K07";
                SA_Delivery_Priority.Text = "13";
            }
            else if (SA_Sales_Group_2.SelectedValue == "K08")
            {
                Is_Sales_Null.Text = "K08";
                SA_Delivery_Priority.Text = "12";
            }
            else if (SA_Sales_Group_2.SelectedValue == "K10")
            {
                Is_Sales_Null.Text = "K10";
                SA_Delivery_Priority.Text = "12";
            }
            else if (SA_Sales_Group_2.SelectedValue == "")
            {
                Is_Sales_Null.Text = "";
                SA_Delivery_Priority.Text = "";
            }
            if (SA_Sales_Group_2.SelectedValue == "K04" && SA_Price_Group_1.Text == "RPL-KC")
            {

                IsRSM_Ship.Text = "Ship";
            }
            else
            {
                IsRSM_Ship.Text = "";
            }
        }
        #endregion

        protected void IsRSM_Ship_TextChanged(object sender, EventArgs e)
        {
            if (SA_Sales_Group_2.SelectedValue == "K04" && SA_Price_Group_1.Text == "RPL-KC")
            {

                IsRSM_Ship.Text = "Ship";
            }
            else
            {
                IsRSM_Ship.Text = "";
            }


        }

        protected void SA_Attributes_7_SelectedIndexChanged(object sender, EventArgs e)
        {
            SA_Attributes_8.Text = "";
            IList<m_Attributes_7> bcc = (m_Attributes_7.status == 1 & (m_Attributes_7.attributes7 == SA_Attributes_7.SelectedValue
                | m_Attributes_7.attributes7 == "")).List<m_Attributes_7>();
            foreach (m_Attributes_7 BC in bcc)
            {

                SA_Attributes_8.Text = BC.Attributes8;

            }
        }



        //protected void SA_Attributes_7_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    SA_Attributes_7.Items.Clear();
        //    SA_Attributes_7.Items.Add(new ListItem("", ""));
        //    IList<m_Attributes_7> bcs1 = (m_Attributes_7.status == 1 & (m_Attributes_7.city_Code_Name == BA_City_Code.SelectedValue
        //        | m_Attributes_7.city_Code_Name == "")).List<m_Attributes_7>();
        //    foreach (m_Attributes_7 BC in bcs1)
        //    {
        //        if (SA_Attributes_7.Items.FindByValue(BC.City_Code_Name) == null)
        //        {
        //            SA_Attributes_7.Items.Add(new ListItem(BC.Attributes7, BC.Attributes7));

        //        }
        //    }
        //}







        #region 控制流程k1
        //protected void SA_Sales_Group_1_TextChanged(object sender, EventArgs e)
        //{
        //    if (SA_Sales_Group_1.Text== "K02")
        //    {
        //        Is_K02_Null.Text = "";
        //    }
        //    else if (SA_Sales_Group_1.Text == "K01")
        //    {
        //        Is_K02_Null.Text = "K01";

        //    }
        //    else if (SA_Sales_Group_1.Text == "K03")
        //    {
        //        Is_K02_Null.Text = "K03";
        //    }
        //    else if (SA_Sales_Group_1.Text == "")
        //    {
        //        Is_K02_Null.Text = "";
        //    }
        //}
        #endregion

        //private List<String> GetShipToDivisionValue()
        //{
        //    if (this.SA_Customer_Division_K1
        //}
        #region 方法 抓取申请人Email
        private List<string> GetEmailByWinId(List<string> winIds)
        {
            if (winIds == null || winIds.Count <= 0) return null;
            const string sql = @"SELECT EMAIL FROM CLIENTS WHERE USERNAME IN ({0})";
            var ds = Storage.Context2.ExecuteDataSet(new Command(string.Format(sql, string.Join(",", winIds.ToArray()))));
            if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return null;
            var ret = new List<string>();
            foreach (System.Data.DataRow r in ds.Tables[0].Rows)
            {
                var email = r[0];
                if (email == null || email == DBNull.Value || ret.Contains(email as string)) continue;
                ret.Add(email as string);
            }
            return ret;
        }
        #endregion



        #region Implementation of ITempSave

        public void SaveData(bool submit)
        {
            try
            {
                if (submit)
                {
                    #region 数据验证
                    List<string> vald_s = new List<string>();
                    List<Regular> regs = new List<Regular>();

                    if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check" || TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Check" || TaskAPI.Step == "DMO Approve") && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                    {
                        vald_s.AddRange(DataValidation());
                        vald_s.AddRange(ShipTo1.DataValidation());
                    }

                    switch (TaskAPI.Step)
                    {
                        case "RSM":
                        case "RPM":
                        case "PC Manager":
                        case "Ship to Mgr":
                        case "SM/PSM/SO":
                        case "CA Check":
                        case "AR":
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                        case "CA Confirm":
                        case "AR Check":
                        case "DMO Change Z1":
                        case "Issue Termination Notice":
                            if (Assessment1.Assessment.Opinion == "2")
                            {
                                regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion:退回时，退回理由(Remark备注) 必填"));
                            }
                            break;

                        //default:
                        //    regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion:申请理由(Remark备注) 必填"));
                        //    break;
                    }

                    vald_s.AddRange(Validation(regs));
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }

                    #endregion

                    #region 引擎传值
                    if (TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check" || TaskAPI.Step == "RSM" || TaskAPI.Step == "RPM" || TaskAPI.Step == "PC Manager" || TaskAPI.Step == "MC" || TaskAPI.Step == "Store Operation" || TaskAPI.Step == "Store Operation Check")
                    {
                        if (TaskAPI.IsInitiate)
                        {
                            TaskAPI.UserName = UserAPI.UserName;
                            ApplicationNo.Text = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                            TaskAPI["ApplicationNo"] = ApplicationNo.Text;
                            TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                            TaskAPI["Applicator"] = UserAPI.UserName;
                            TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                            //TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                            var applicatorEmail = GetEmailByWinId(new List<string> { "'" + UserAPI.UserName + "'" });
                            TaskAPI["ApplicatorEmail"] = applicatorEmail != null && applicatorEmail.Count > 0
                                                         ? applicatorEmail[0]
                                                         : string.Empty;
                            TaskAPI["Department"] = UserAPI.Department;
                            TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                            TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;
                            TaskAPI["Time"] = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                            if (!String.IsNullOrEmpty(ApplicationNo.Text))
                            {
                                TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text)
                                       + " / " + ApplicationNo.Text + (Keys.Items[0].Selected ? " / Sold To " : "") + (Keys.Items[1].Selected ? " / Ship To " : "") + (Keys.Items[2].Selected ? " / Hierarchy Notes " : "");
                            }

                        }

                        //TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text)
                        //                + " / " + ApplicationNo.Text + (Keys.Items[0].Selected ? " / Sold To " : "") + (Keys.Items[1].Selected ? " / Ship To " : "") + (Keys.Items[2].Selected ? " / Hierarchy Notes " : "");

                        TaskAPI["isHierarchy"] = Hierarchy.Visible ? "1" : "0";
                        TaskAPI["isSold"] = SoldTo.Visible ? "1" : "0";
                        TaskAPI["isShip"] = ShipTo.Visible ? "1" : "0";

                        TaskAPI["Actions"] = Actions.SelectedValue;
                        TaskAPI["BA_Industry3"] = BA_Industry3.Text;
                        TaskAPI["BA_Industry2"] = BA_Industry2.Text;
                        TaskAPI["BA_Hierarchy_2"] = BA_Hierarchy_2.Text;
                        TaskAPI["BA_Hierarchy_1"] = BA_Hierarchy_1.Text;
                        TaskAPI["IsCN88"] = BA_Sales_Office.Text;

                        TaskAPI["SA_Division_K1"] = SA_Customer_Division_K1.Checked ? "1" : "0";
                        TaskAPI["SA_Division_K2"] = SA_Customer_Division_K2.Checked ? "1" : "0";
                        TaskAPI["SA_Division_K3"] = SA_Customer_Division_K3.Checked ? "1" : "0";
                        TaskAPI["SA_Sales_Group_2"] = SA_Sales_Group_2.SelectedValue;
                        TaskAPI["ST_SD_Division"] = ShipTo1.ST_SD_Division.Text;
                        TaskAPI["ST_Sales_Group"] = ShipTo1.ST_Sales_Group.SelectedValue;

                        TaskAPI["IsDivision_Null"] = ShipTo1.IsDivision_Null.Text;
                        TaskAPI["Is_Sales_Null"] = Is_Sales_Null.Text;
                        TaskAPI["Is_K02_Null"] = Is_K02_Null.Text;

                        TaskAPI["IsRSM_Ship"] = IsRSM_Ship.Text;

                        TaskAPI["Is_PC"] = ShipTo1.Is_PC.Text;
                        TaskAPI["ST_Division"] = ShipTo1.ST_Division.SelectedValue;
                        //TaskAPI["EMAIL_" + TaskAPI.Step.Replace(" ", "_")] = UserAPI.Mail;
                        if (TaskAPI.IsBeginStep)
                        {
                            #region 从数据库取得流程步骤处理人
                            if (TaskAPI.IsBeginStep)
                            {
                                SortedList<string, string> rec_a = new SortedList<string, string>();
                                IList<cmd_Recipient> rec_s = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.status == 1
                                                            & cmd_Recipient.step.In(new string[8] { "DMO Approve", "DMO Maintain", "DMO Check", "AR", "CCC", "DMO Change Z1", "AR Check", "Issue Termination Notice" })).List<cmd_Recipient>();
                                foreach (cmd_Recipient rec in rec_s)
                                {
                                    if (!rec_a.ContainsKey(rec.Step))
                                    {
                                        rec_a.Add(rec.Step, rec.Recipient);
                                        continue;
                                    }

                                    if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                                    {
                                        continue;
                                    }
                                    rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                                }

                                //步骤处理人赋值
                                for (int i = 0; i < rec_a.Keys.Count; i++)
                                {
                                    TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_").Replace("/", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                }
                                //TaskAPI["EMAIL_" + TaskAPI.Step.Replace(" ", "_")] = UserAPI.Mail;

                            }
                            #endregion

                            #region RSM、RPM、PC Manager、SM/PSM/SO
                            if (Keys.Items[0].Selected)
                            {

                                string division1 = "";
                                string division = "";
                                if (SA_Customer_Division_K1.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_1.Text != "K02")
                                    {
                                        division = "K1";
                                    }
                                    else
                                    {
                                        division = "K9";
                                    }
                                }

                                else if (SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_2.SelectedValue != "K04")
                                    {
                                        division = "K2";
                                    }
                                    else
                                    {
                                        division = "K1";
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked)
                                {
                                    division = "K3";
                                }
                                else if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Customer_Division_K1.Checked)
                                    {
                                        if (SA_Sales_Group_1.Text != "K02")
                                        {
                                            division1 = "K1";
                                        }
                                        else
                                        {
                                            division1 = "K9";
                                        }

                                        if (SA_Sales_Group_2.SelectedValue != "K04")
                                        {
                                            division = "K2";
                                        }
                                        else
                                        {
                                            division = "K1";
                                        }
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K1.Checked)
                                {
                                    division1 = "K2";
                                    division = "K1";
                                }




                                List<string> cmd_tar = new List<string>();
                                List<string> cmd_tar2 = new List<string>();
                                List<string> cmd_tar3 = new List<string>();

                                //新增 tar4
                                List<string> cmd_tar4 = new List<string>();
                                List<string> cmd_tar5 = new List<string>();
                                List<string> cmd_tar6 = new List<string>();
                                List<string> cmd_tar7 = new List<string>();
                                List<string> cmd_tar8 = new List<string>();
                                //

                                string region = BA_Region.SelectedValue.Length >= 6 ? BA_Region.SelectedValue.Substring(3, 3) : BA_Region.SelectedValue;

                                IList<cmd_Recipient> cmd_src = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[8] { "RSM", "RPM", "PC Manager", "SM/PSM/SO", "CA Check", "MC", "Store Operation", "Store Operation Check" })
                                                              & cmd_Recipient.salesOffice == (BA_Sales_Office.Text.Length > 3 ? BA_Sales_Office.SelectedValue.Substring(0, 4) : BA_Sales_Office.Text) & (cmd_Recipient.division == division | (cmd_Recipient.division == division1))).List<cmd_Recipient>();


                                foreach (cmd_Recipient cmd_r in cmd_src)
                                {
                                    if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar3.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar.Add(cmd_r.Recipient);
                                        continue;
                                    }

                                    //新增 tar4
                                    if (!cmd_tar4.Contains(cmd_r.Recipient) && cmd_r.Step == "RPM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar4.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar5.Contains(cmd_r.Recipient) && cmd_r.Step == "PC Manager" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar5.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar6.Contains(cmd_r.Recipient) && cmd_r.Step == "MC" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar6.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar7.Contains(cmd_r.Recipient) && cmd_r.Step == "Store Operation" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar7.Add(cmd_r.Recipient);
                                        continue;
                                    }

                                    if (!cmd_tar8.Contains(cmd_r.Recipient) && cmd_r.Step == "Store Operation Check" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar8.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    //

                                    if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar2.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                }

                                TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                //新增 tar4
                                TaskAPI["R_RPM"] = cmd_tar4.Count == 0 ? new string[1] { "" } : cmd_tar4.ToArray();
                                TaskAPI["R_PC_Manager"] = cmd_tar5.Count == 0 ? new string[1] { "" } : cmd_tar5.ToArray();
                                TaskAPI["R_MC"] = cmd_tar6.Count == 0 ? new string[1] { "" } : cmd_tar6.ToArray();
                                TaskAPI["R_Store_Operation"] = cmd_tar7.Count == 0 ? new string[1] { "" } : cmd_tar7.ToArray();
                                TaskAPI["R_Store_Operation_Check"] = cmd_tar8.Count == 0 ? new string[1] { "" } : cmd_tar8.ToArray();
                                //

                                TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                // TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();


                                bool falg_dt = false;
                                TaskDB db = new TaskDB();
                                db.Storage("bpmDB");
                                DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        if (dt.Rows[i][0].ToString() == "S")
                                        {
                                            falg_dt = true;
                                            break;
                                        }
                                    }
                                }
                                if (!falg_dt)
                                {

                                    TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                }

                            }
                            else
                            {
                                List<string> cmd_tar = new List<string>();
                                List<string> cmd_tar2 = new List<string>();
                                List<string> cmd_tar4 = new List<string>();
                                List<string> cmd_tar5 = new List<string>();
                                List<string> cmd_tar3 = new List<string>();

                                if (Keys.Items[1].Selected)
                                {
                                    string region = ShipTo1.ShipTos[0].ST_SD_Region.Length >= 1 ? ShipTo1.ShipTos[0].ST_SD_Region.Substring(0, 3) : ShipTo1.ShipTos[0].ST_SD_Region;
                                    IList<cmd_Recipient> cmd_src = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[5] { "RSM", "RPM", "PC Manager", "SM/PSM/SO", "CA Check" })
                                                                  & cmd_Recipient.salesOffice == (ShipTo1.ShipTos[0].ST_SD_Sales_Office.Length > 1 ? ShipTo1.ShipTos[0].ST_SD_Sales_Office.Substring(0, 4) : ShipTo1.ShipTos[0].ST_SD_Sales_Office) & cmd_Recipient.division == ShipTo1.ShipTos[0].ST_SD_Division).List<cmd_Recipient>();
                                    foreach (cmd_Recipient cmd_r in cmd_src)
                                    {
                                        if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar3.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                            continue;
                                        }

                                        if (!cmd_tar4.Contains(cmd_r.Recipient) && cmd_r.Step == "RPM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar4.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar5.Contains(cmd_r.Recipient) && cmd_r.Step == "PC Manager" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar5.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar2.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                    }

                                    TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                    TaskAPI["R_RPM"] = cmd_tar4.Count == 0 ? new string[1] { "" } : cmd_tar4.ToArray();
                                    TaskAPI["R_PC_Manager"] = cmd_tar5.Count == 0 ? new string[1] { "" } : cmd_tar5.ToArray();
                                    TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                    //TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();

                                    bool falg_dt = false;
                                    TaskDB db = new TaskDB();
                                    db.Storage("bpmDB");
                                    DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                    if (dt.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            if (dt.Rows[i][0].ToString() == "S")
                                            {
                                                falg_dt = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!falg_dt)
                                    {

                                        TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                    }

                                }
                                else
                                {
                                    string division = "";
                                    if (NA_Customer_Division_K1.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K1.Checked && NA_Customer_Division_K2.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K1.Checked && NA_Customer_Division_K2.Checked && NA_Customer_Division_K3.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K2.Checked && !NA_Customer_Division_K1.Checked)
                                    {
                                        division += (string.IsNullOrEmpty(division) ? "" : "/") + "K2";
                                    }

                                    if (NA_Customer_Division_K3.Checked)
                                    {
                                        division += (string.IsNullOrEmpty(division) ? "" : "/") + "K3";
                                    }
                                    //List<string> cmd_tar = new List<string>();
                                    //List<string> cmd_tar2 = new List<string>();
                                    //List<string> cmd_tar3 = new List<string>();
                                    //string region = NA_Region.SelectedValue.Length >= 6 ? NA_Region.SelectedValue.Substring(3, 3) : NA_Region.SelectedValue;

                                    IList<cmd_Recipient> cmd_src1 = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[2] { "RSM", "SM/PSM/SO" })
                                                                  & cmd_Recipient.salesOffice == (NA_Sales_Office_1.Text.Length > 1 ? NA_Sales_Office_1.Text.Substring(0, 4) : NA_Sales_Office_1.Text) & cmd_Recipient.division == division).List<cmd_Recipient>();

                                    foreach (cmd_Recipient cmd_r in cmd_src1)
                                    {
                                        //if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        //{
                                        //    cmd_tar3.Add(cmd_r.Recipient);
                                        //    continue;
                                        //}
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM")
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO")
                                        {
                                            cmd_tar2.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                    }

                                    TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                    TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                    //TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();

                                    bool falg_dt = false;
                                    TaskDB db = new TaskDB();
                                    db.Storage("bpmDB");
                                    DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                    if (dt.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            if (dt.Rows[i][0].ToString() == "S")
                                            {
                                                falg_dt = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!falg_dt)
                                    {

                                        TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                    }

                                }
                            }

                            #endregion

                            #region Ship to Mgr、IsNeedST、IsNeedK1
                            TaskAPI["IsNeedST"] = "0";
                            TaskAPI["IsNeedK1"] = "0";
                            if (Keys.Items[0].Selected && Keys.Items[1].Selected)
                            {
                                List<string> cmd_tar = new List<string>();
                                string division = "";
                                string division1 = "";
                                if (SA_Customer_Division_K1.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_1.Text != "K02")
                                    {
                                        division = "K1";
                                    }
                                    else
                                    {
                                        division = "K9";
                                    }
                                }

                                else if (SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_2.SelectedValue != "K04")
                                    {
                                        division = "K2";
                                    }
                                    else
                                    {
                                        division = "K1";
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked)
                                {
                                    division = "K3";
                                }
                                else if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Customer_Division_K1.Checked)
                                    {
                                        if (SA_Sales_Group_1.Text != "K02")
                                        {
                                            division1 = "K1";
                                        }
                                        else
                                        {
                                            division1 = "K9";
                                        }

                                        if (SA_Sales_Group_2.SelectedValue != "K04")
                                        {
                                            division = "K2";
                                        }
                                        else
                                        {
                                            division = "K1";
                                        }
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K1.Checked)
                                {
                                    division1 = "K2";
                                    division = "K1";
                                }


                                //if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K3.Checked)
                                //{
                                //    division = "K1";
                                //}





                                int k1_num = 0;
                                int k1_num_all = 0;
                                //int.TryParse(BA_County_Code.Text.Length < 2 ? "" : BA_County_Code.Text.Substring(BA_County_Code.Text.Length - 2, 2), out k1_num_all);



                                Expression exp = new Expression();
                                bool flg = true;
                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {
                                    if ((!string.IsNullOrEmpty(st.ST_Sales_Office) && st.ST_Sales_Office != BA_Sales_Office.SelectedValue))
                                    {
                                        if (exp.Parameters.Count == 0)
                                        {
                                            exp = (cmd_Recipient.division == st.ST_SD_Division
                                                 & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 3 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                        else
                                        {
                                            exp |= (cmd_Recipient.division == st.ST_SD_Division
                                                  & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 3 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(st.ST_Division) && st.ST_Division == "K1" && flg)
                                    //if (BA_Sales_Employee_K1.Text!="" && BA_Sales_Employee_K2.Text == "")
                                    {
                                        int k1_num_t = 0;
                                        int k1_num_all_t = 0;
                                        int.TryParse(st.ST_Total_ST, out k1_num_t);


                                        switch (BA_County_Code.Text)
                                        {
                                            case "K01":
                                                k1_num_all_t = 3;
                                                break;
                                            case "K02":
                                                k1_num_all_t = 2;
                                                break;
                                            case "K03":
                                                k1_num_all_t = 1;
                                                break;
                                            case "K04":
                                                k1_num_all_t = 1;
                                                break;
                                        }

                                        k1_num += k1_num_t;
                                        k1_num_all += k1_num_all_t;
                                        flg = false;
                                    }
                                }



                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {
                                    if (exp.SqlText.Length > 0)
                                    {
                                        string region = st.ST_Region.Length >= 1 ? st.ST_Region.Substring(3, 3) : st.ST_Region;
                                        IList<cmd_Recipient> cmd_src = (cmd_Recipient.step == "Ship to Mgr" & (exp)).List<cmd_Recipient>();
                                        foreach (cmd_Recipient cmd_r in cmd_src)
                                        {
                                            if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "Ship to Mgr" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                            {
                                                cmd_tar.Add(cmd_r.Recipient);
                                            }
                                        }
                                    }
                                }

                                TaskAPI["R_Ship_to_Mgr"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                TaskAPI["IsNeedST"] = cmd_tar.Count > 0 ? "1" : "0";
                                //TaskAPI["IsNeedK1"] = division.IndexOf("K1") != -1 && k1_num_all > 0 && k1_num + ShipTo1.ShipTos.Count > k1_num_all ? "1" : "0";


                                //if (ShipTo1.ST_Division.SelectedValue == "K1")
                                //{
                                TaskAPI["IsNeedK1"] = k1_num_all > 0 && k1_num + CalculateK1Count() > k1_num_all ? "1" : "0";
                                //}
                            }
                            else if (Keys.Items[1].Selected)
                            {
                                int k1_num = 0;
                                int k1_num_all = 0;

                                List<string> cmd_tar = new List<string>();
                                string division = "";

                                Expression exp = new Expression();
                                bool flg = true;
                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {

                                    if ((!string.IsNullOrEmpty(st.ST_Sales_Office) && st.ST_Sales_Office.Substring(0, 4) != st.ST_SD_Sales_Office))
                                    {
                                        if (exp.Parameters.Count == 0)
                                        {
                                            exp = (cmd_Recipient.division == st.ST_SD_Division
                                                 & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 1 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                        else
                                        {
                                            exp |= (cmd_Recipient.division == st.ST_SD_Division
                                                  & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 1 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                    }
                                    if (!string.IsNullOrEmpty(st.ST_Division) && st.ST_Division == "K1" && flg)
                                    {
                                        int k1_num_t = 0;
                                        int k1_num_all_t = 0;
                                        int.TryParse(st.ST_Total_ST, out k1_num_t);


                                        //int.TryParse(string.IsNullOrEmpty(st.ST_SD_County_Code) || st.ST_SD_County_Code.Length < 2 ? "" : st.ST_SD_County_Code.Substring(st.ST_SD_County_Code.Length - 2, 2), out k1_num_all_t);
                                        switch (st.ST_SD_County_Code)
                                        {
                                            case "K01":
                                                k1_num_all_t = 3;
                                                break;
                                            case "K02":
                                                k1_num_all_t = 2;
                                                break;
                                            case "K03":
                                                k1_num_all_t = 1;
                                                break;
                                            case "K04":
                                                k1_num_all_t = 1;
                                                break;
                                        }

                                        k1_num += k1_num_t;
                                        k1_num_all += k1_num_all_t;
                                        flg = false;
                                    }
                                }

                                if (exp.SqlText.Length > 0)
                                {
                                    string region = ShipTo1.ShipTos[0].ST_Region.Length >= 1 ? ShipTo1.ShipTos[0].ST_Region.Substring(3, 3) : ShipTo1.ShipTos[0].ST_Region;
                                    IList<cmd_Recipient> cmd_src = (cmd_Recipient.step == "Ship to Mgr" & (exp)).List<cmd_Recipient>();
                                    foreach (cmd_Recipient cmd_r in cmd_src)
                                    {
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "Ship to Mgr" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                        }
                                    }
                                }
                                //if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                //{
                                //    cmd_tar2.Add(cmd_r.Recipient);
                                //    continue;
                                //}

                                TaskAPI["R_Ship_to_Mgr"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                TaskAPI["IsNeedST"] = cmd_tar.Count > 0 ? "1" : "0";
                                //TaskAPI["IsNeedK1"] = division.IndexOf("K1") != -1 && k1_num_all > 0 && k1_num + ShipTo1.ShipTos.Count > k1_num_all ? "1" : "0";
                                //if (ShipTo1.ST_Division.SelectedValue == "K1")
                                //{
                                TaskAPI["IsNeedK1"] = k1_num_all > 0 && k1_num + CalculateK1Count() > k1_num_all ? "1" : "0";
                                //
                            }

                            #endregion



                        }
                        else if (TaskAPI.Step == "CA Check")
                        {


                            #region RSM、RPM、PC Manager、SM/PSM/SO
                            if (Keys.Items[0].Selected)
                            {

                                string division1 = "";
                                string division = "";
                                if (SA_Customer_Division_K1.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_1.Text != "K02")
                                    {
                                        division = "K1";
                                    }
                                    else
                                    {
                                        division = "K9";
                                    }
                                }

                                else if (SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_2.SelectedValue != "K04")
                                    {
                                        division = "K2";
                                    }
                                    else
                                    {
                                        division = "K1";
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked)
                                {
                                    division = "K3";
                                }
                                else if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Customer_Division_K1.Checked)
                                    {
                                        if (SA_Sales_Group_1.Text != "K02")
                                        {
                                            division1 = "K1";
                                        }
                                        else
                                        {
                                            division1 = "K9";
                                        }

                                        if (SA_Sales_Group_2.SelectedValue != "K04")
                                        {
                                            division = "K2";
                                        }
                                        else
                                        {
                                            division = "K1";
                                        }
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K1.Checked)
                                {
                                    division1 = "K2";
                                    division = "K1";
                                }




                                List<string> cmd_tar = new List<string>();
                                List<string> cmd_tar2 = new List<string>();
                                List<string> cmd_tar3 = new List<string>();

                                //新增 tar4
                                List<string> cmd_tar4 = new List<string>();
                                List<string> cmd_tar5 = new List<string>();
                                List<string> cmd_tar6 = new List<string>();
                                List<string> cmd_tar7 = new List<string>();
                                List<string> cmd_tar8 = new List<string>();
                                //

                                string region = BA_Region.SelectedValue.Length >= 6 ? BA_Region.SelectedValue.Substring(3, 3) : BA_Region.SelectedValue;

                                IList<cmd_Recipient> cmd_src = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[8] { "RSM", "RPM", "PC Manager", "SM/PSM/SO", "CA Check", "MC", "Store Operation", "Store Operation Check" })
                                                              & cmd_Recipient.salesOffice == (BA_Sales_Office.Text.Length > 3 ? BA_Sales_Office.SelectedValue.Substring(0, 4) : BA_Sales_Office.Text) & (cmd_Recipient.division == division | (cmd_Recipient.division == division1))).List<cmd_Recipient>();


                                foreach (cmd_Recipient cmd_r in cmd_src)
                                {
                                    if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar3.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar.Add(cmd_r.Recipient);
                                        continue;
                                    }

                                    //新增 tar4
                                    if (!cmd_tar4.Contains(cmd_r.Recipient) && cmd_r.Step == "RPM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar4.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar5.Contains(cmd_r.Recipient) && cmd_r.Step == "PC Manager" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar5.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar6.Contains(cmd_r.Recipient) && cmd_r.Step == "MC" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar6.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    if (!cmd_tar7.Contains(cmd_r.Recipient) && cmd_r.Step == "Store Operation" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar7.Add(cmd_r.Recipient);
                                        continue;
                                    }

                                    if (!cmd_tar8.Contains(cmd_r.Recipient) && cmd_r.Step == "Store Operation Check" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar8.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                    //

                                    if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                    {
                                        cmd_tar2.Add(cmd_r.Recipient);
                                        continue;
                                    }
                                }

                                TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                //新增 tar4
                                TaskAPI["R_RPM"] = cmd_tar4.Count == 0 ? new string[1] { "" } : cmd_tar4.ToArray();
                                TaskAPI["R_PC_Manager"] = cmd_tar5.Count == 0 ? new string[1] { "" } : cmd_tar5.ToArray();
                                TaskAPI["R_MC"] = cmd_tar6.Count == 0 ? new string[1] { "" } : cmd_tar6.ToArray();
                                TaskAPI["R_Store_Operation"] = cmd_tar7.Count == 0 ? new string[1] { "" } : cmd_tar7.ToArray();
                                TaskAPI["R_Store_Operation_Check"] = cmd_tar8.Count == 0 ? new string[1] { "" } : cmd_tar8.ToArray();
                                //
                                TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                // TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();


                                bool falg_dt = false;
                                TaskDB db = new TaskDB();
                                db.Storage("bpmDB");
                                DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        if (dt.Rows[i][0].ToString() == "S")
                                        {
                                            falg_dt = true;
                                            break;
                                        }
                                    }
                                }
                                if (!falg_dt)
                                {

                                    TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                }

                            }
                            else
                            {
                                List<string> cmd_tar = new List<string>();
                                List<string> cmd_tar2 = new List<string>();
                                List<string> cmd_tar4 = new List<string>();
                                List<string> cmd_tar5 = new List<string>();
                                List<string> cmd_tar3 = new List<string>();

                                if (Keys.Items[1].Selected)
                                {
                                    string region = ShipTo1.ShipTos[0].ST_SD_Region.Length >= 1 ? ShipTo1.ShipTos[0].ST_SD_Region.Substring(0, 3) : ShipTo1.ShipTos[0].ST_SD_Region;
                                    IList<cmd_Recipient> cmd_src = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[5] { "RSM", "RPM", "PC Manager", "SM/PSM/SO", "CA Check" })
                                                                  & cmd_Recipient.salesOffice == (ShipTo1.ShipTos[0].ST_SD_Sales_Office.Length > 1 ? ShipTo1.ShipTos[0].ST_SD_Sales_Office.Substring(0, 4) : ShipTo1.ShipTos[0].ST_SD_Sales_Office) & cmd_Recipient.division == ShipTo1.ShipTos[0].ST_SD_Division).List<cmd_Recipient>();
                                    foreach (cmd_Recipient cmd_r in cmd_src)
                                    {
                                        if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar3.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                            continue;
                                        }

                                        if (!cmd_tar4.Contains(cmd_r.Recipient) && cmd_r.Step == "RPM" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar4.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar5.Contains(cmd_r.Recipient) && cmd_r.Step == "PC Manager" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar5.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar2.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                    }

                                    TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                    TaskAPI["R_RPM"] = cmd_tar4.Count == 0 ? new string[1] { "" } : cmd_tar4.ToArray();
                                    TaskAPI["R_PC_Manager"] = cmd_tar5.Count == 0 ? new string[1] { "" } : cmd_tar5.ToArray();
                                    TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                    //TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();

                                    bool falg_dt = false;
                                    TaskDB db = new TaskDB();
                                    db.Storage("bpmDB");
                                    DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                    if (dt.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            if (dt.Rows[i][0].ToString() == "S")
                                            {
                                                falg_dt = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!falg_dt)
                                    {

                                        TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                    }

                                }
                                else
                                {
                                    string division = "";
                                    if (NA_Customer_Division_K1.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K1.Checked && NA_Customer_Division_K2.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K1.Checked && NA_Customer_Division_K2.Checked && NA_Customer_Division_K3.Checked)
                                    {
                                        division = "K1";
                                    }

                                    if (NA_Customer_Division_K2.Checked && !NA_Customer_Division_K1.Checked)
                                    {
                                        division += (string.IsNullOrEmpty(division) ? "" : "/") + "K2";
                                    }

                                    if (NA_Customer_Division_K3.Checked)
                                    {
                                        division += (string.IsNullOrEmpty(division) ? "" : "/") + "K3";
                                    }
                                    //List<string> cmd_tar = new List<string>();
                                    //List<string> cmd_tar2 = new List<string>();
                                    //List<string> cmd_tar3 = new List<string>();
                                    //string region = NA_Region.SelectedValue.Length >= 6 ? NA_Region.SelectedValue.Substring(3, 3) : NA_Region.SelectedValue;

                                    IList<cmd_Recipient> cmd_src1 = (cmd_Recipient.process == TaskAPI.Process & cmd_Recipient.step.In(new string[2] { "RSM", "SM/PSM/SO" })
                                                                  & cmd_Recipient.salesOffice == (NA_Sales_Office_1.Text.Length > 1 ? NA_Sales_Office_1.Text.Substring(0, 4) : NA_Sales_Office_1.Text) & cmd_Recipient.division == division).List<cmd_Recipient>();

                                    foreach (cmd_Recipient cmd_r in cmd_src1)
                                    {
                                        //if (!cmd_tar3.Contains(cmd_r.Recipient) && cmd_r.Step.ToUpper() == "CA CHECK" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        //{
                                        //    cmd_tar3.Add(cmd_r.Recipient);
                                        //    continue;
                                        //}
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "RSM")
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                        if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO")
                                        {
                                            cmd_tar2.Add(cmd_r.Recipient);
                                            continue;
                                        }
                                    }

                                    TaskAPI["R_RSM"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                    TaskAPI["R_SM_PSM_SO"] = cmd_tar2.Count == 0 ? new string[1] { "" } : cmd_tar2.ToArray();
                                    //TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();

                                    bool falg_dt = false;
                                    TaskDB db = new TaskDB();
                                    db.Storage("bpmDB");
                                    DataTable dt = db.Query(" select steplabel from  TASKS where processname='" + TaskAPI.Process + "' and  Incident=" + TaskAPI.Incident + " ");
                                    if (dt.Rows.Count > 0)
                                    {
                                        for (int i = 0; i < dt.Rows.Count; i++)
                                        {
                                            if (dt.Rows[i][0].ToString() == "S")
                                            {
                                                falg_dt = true;
                                                break;
                                            }
                                        }
                                    }
                                    if (!falg_dt)
                                    {

                                        TaskAPI["R_CA_Check"] = cmd_tar3.Count == 0 ? new string[1] { "" } : cmd_tar3.ToArray();
                                    }

                                }
                            }

                            #endregion

                            #region Ship to Mgr、IsNeedST、IsNeedK1
                            TaskAPI["IsNeedST"] = "0";
                            TaskAPI["IsNeedK1"] = "0";
                            if (Keys.Items[0].Selected && Keys.Items[1].Selected)
                            {
                                List<string> cmd_tar = new List<string>();
                                string division = "";
                                string division1 = "";
                                if (SA_Customer_Division_K1.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_1.Text != "K02")
                                    {
                                        division = "K1";
                                    }
                                    else
                                    {
                                        division = "K9";
                                    }
                                }

                                else if (SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Sales_Group_2.SelectedValue != "K04")
                                    {
                                        division = "K2";
                                    }
                                    else
                                    {
                                        division = "K1";
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && !SA_Customer_Division_K2.Checked && !SA_Customer_Division_K1.Checked)
                                {
                                    division = "K3";
                                }
                                else if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && !SA_Customer_Division_K3.Checked)
                                {
                                    if (SA_Customer_Division_K1.Checked)
                                    {
                                        if (SA_Sales_Group_1.Text != "K02")
                                        {
                                            division1 = "K1";
                                        }
                                        else
                                        {
                                            division1 = "K9";
                                        }

                                        if (SA_Sales_Group_2.SelectedValue != "K04")
                                        {
                                            division = "K2";
                                        }
                                        else
                                        {
                                            division = "K1";
                                        }
                                    }
                                }
                                else if (SA_Customer_Division_K3.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K1.Checked)
                                {
                                    division1 = "K2";
                                    division = "K1";
                                }


                                //if (SA_Customer_Division_K1.Checked && SA_Customer_Division_K2.Checked && SA_Customer_Division_K3.Checked)
                                //{
                                //    division = "K1";
                                //}





                                int k1_num = 0;
                                int k1_num_all = 0;
                                //int.TryParse(BA_County_Code.Text.Length < 2 ? "" : BA_County_Code.Text.Substring(BA_County_Code.Text.Length - 2, 2), out k1_num_all);



                                Expression exp = new Expression();
                                bool flg = true;
                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {
                                    if ((!string.IsNullOrEmpty(st.ST_Sales_Office) && st.ST_Sales_Office != BA_Sales_Office.SelectedValue))
                                    {
                                        if (exp.Parameters.Count == 0)
                                        {
                                            exp = (cmd_Recipient.division == st.ST_SD_Division
                                                 & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 3 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                        else
                                        {
                                            exp |= (cmd_Recipient.division == st.ST_SD_Division
                                                  & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 3 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                    }

                                    if (!string.IsNullOrEmpty(st.ST_Division) && st.ST_Division == "K1" && flg)
                                    //if (BA_Sales_Employee_K1.Text!="" && BA_Sales_Employee_K2.Text == "")
                                    {
                                        int k1_num_t = 0;
                                        int k1_num_all_t = 0;
                                        int.TryParse(st.ST_Total_ST, out k1_num_t);


                                        switch (BA_County_Code.Text)
                                        {
                                            case "K01":
                                                k1_num_all_t = 3;
                                                break;
                                            case "K02":
                                                k1_num_all_t = 2;
                                                break;
                                            case "K03":
                                                k1_num_all_t = 1;
                                                break;
                                            case "K04":
                                                k1_num_all_t = 1;
                                                break;
                                        }

                                        k1_num += k1_num_t;
                                        k1_num_all += k1_num_all_t;
                                        flg = false;
                                    }
                                }



                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {
                                    if (exp.SqlText.Length > 0)
                                    {
                                        string region = st.ST_Region.Length >= 1 ? st.ST_Region.Substring(3, 3) : st.ST_Region;
                                        IList<cmd_Recipient> cmd_src = (cmd_Recipient.step == "Ship to Mgr" & (exp)).List<cmd_Recipient>();
                                        foreach (cmd_Recipient cmd_r in cmd_src)
                                        {
                                            if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "Ship to Mgr" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                            {
                                                cmd_tar.Add(cmd_r.Recipient);
                                            }
                                        }
                                    }
                                }

                                TaskAPI["R_Ship_to_Mgr"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                TaskAPI["IsNeedST"] = cmd_tar.Count > 0 ? "1" : "0";
                                //TaskAPI["IsNeedK1"] = division.IndexOf("K1") != -1 && k1_num_all > 0 && k1_num + ShipTo1.ShipTos.Count > k1_num_all ? "1" : "0";


                                //if (ShipTo1.ST_Division.SelectedValue == "K1")
                                //{
                                TaskAPI["IsNeedK1"] = k1_num_all > 0 && k1_num + CalculateK1Count() > k1_num_all ? "1" : "0";
                                //}
                            }
                            else if (Keys.Items[1].Selected)
                            {
                                int k1_num = 0;
                                int k1_num_all = 0;

                                List<string> cmd_tar = new List<string>();
                                string division = "";

                                Expression exp = new Expression();
                                bool flg = true;
                                foreach (cmd_ShipTo st in ShipTo1.ShipTos)
                                {

                                    if ((!string.IsNullOrEmpty(st.ST_Sales_Office) && st.ST_Sales_Office.Substring(0, 4) != st.ST_SD_Sales_Office))
                                    {
                                        if (exp.Parameters.Count == 0)
                                        {
                                            exp = (cmd_Recipient.division == st.ST_SD_Division
                                                 & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 1 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                        else
                                        {
                                            exp |= (cmd_Recipient.division == st.ST_SD_Division
                                                  & cmd_Recipient.salesOffice == (st.ST_Sales_Office.Length > 1 ? st.ST_Sales_Office.Substring(0, 4) : st.ST_Sales_Office));
                                        }
                                    }
                                    if (!string.IsNullOrEmpty(st.ST_Division) && st.ST_Division == "K1" && flg)
                                    {
                                        int k1_num_t = 0;
                                        int k1_num_all_t = 0;
                                        int.TryParse(st.ST_Total_ST, out k1_num_t);


                                        //int.TryParse(string.IsNullOrEmpty(st.ST_SD_County_Code) || st.ST_SD_County_Code.Length < 2 ? "" : st.ST_SD_County_Code.Substring(st.ST_SD_County_Code.Length - 2, 2), out k1_num_all_t);
                                        switch (st.ST_SD_County_Code)
                                        {
                                            case "K01":
                                                k1_num_all_t = 3;
                                                break;
                                            case "K02":
                                                k1_num_all_t = 2;
                                                break;
                                            case "K03":
                                                k1_num_all_t = 1;
                                                break;
                                            case "K04":
                                                k1_num_all_t = 1;
                                                break;
                                        }

                                        k1_num += k1_num_t;
                                        k1_num_all += k1_num_all_t;
                                        flg = false;
                                    }
                                }

                                if (exp.SqlText.Length > 0)
                                {
                                    string region = ShipTo1.ShipTos[0].ST_Region.Length >= 1 ? ShipTo1.ShipTos[0].ST_Region.Substring(3, 3) : ShipTo1.ShipTos[0].ST_Region;
                                    IList<cmd_Recipient> cmd_src = (cmd_Recipient.step == "Ship to Mgr" & (exp)).List<cmd_Recipient>();
                                    foreach (cmd_Recipient cmd_r in cmd_src)
                                    {
                                        if (!cmd_tar.Contains(cmd_r.Recipient) && cmd_r.Step == "Ship to Mgr" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                        {
                                            cmd_tar.Add(cmd_r.Recipient);
                                        }
                                    }
                                }
                                //if (!cmd_tar2.Contains(cmd_r.Recipient) && cmd_r.Step == "SM/PSM/SO" & (cmd_r.Region == region || cmd_r.Region == "*"))
                                //{
                                //    cmd_tar2.Add(cmd_r.Recipient);
                                //    continue;
                                //}

                                TaskAPI["R_Ship_to_Mgr"] = cmd_tar.Count == 0 ? new string[1] { "" } : cmd_tar.ToArray();
                                TaskAPI["IsNeedST"] = cmd_tar.Count > 0 ? "1" : "0";
                                //TaskAPI["IsNeedK1"] = division.IndexOf("K1") != -1 && k1_num_all > 0 && k1_num + ShipTo1.ShipTos.Count > k1_num_all ? "1" : "0";
                                //if (ShipTo1.ST_Division.SelectedValue == "K1")
                                //{
                                TaskAPI["IsNeedK1"] = k1_num_all > 0 && k1_num + CalculateK1Count() > k1_num_all ? "1" : "0";
                                //
                            }

                            #endregion

                        }

                    }

                    if (!TaskAPI.IsBeginStep)
                    {
                        TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                        TaskAPI["TaskID"] = TaskAPI.TaskID;
                        //}

                        #region 退回到某个步骤的处理人
                        if (TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] != null)
                        {
                            object[] obj = (object[])(TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")]);
                            for (int i = 0; i < obj.Length; i++)
                            {
                                obj[i] = null;
                            }

                            obj[0] = UserAPI.UserName;

                            TaskAPI["R_" + TaskAPI.Step.Replace(" ", "_").Replace("/", "_")] = obj;

                        }
                        #endregion
                    }

                    //#region 退回步骤并返回功能 传值
                    //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    //{
                    //    TaskAPI["Step"] = Assessment1.JumpStep;
                    //    TaskAPI["PreStep"] = TaskAPI.Step;
                    //}
                    //else
                    //{
                    //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                    //    if (PreStep.Trim() != "")
                    //    {
                    //        TaskAPI["Step"] = PreStep;
                    //        TaskAPI["PreStep"] = "";
                    //    }
                    //    else
                    //    {
                    //        TaskAPI["Step"] = "";
                    //        TaskAPI["PreStep"] = "";
                    //    }
                    //}

                    //#endregion


                    #endregion
                }

                #region 提交步骤
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        #region 第一步存值

                        cmd_Customer cst = new cmd_Customer();
                        if ((cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident & cmd_Customer.user == UserAPI.UserName).Count<cmd_Customer>() > 0)
                        {
                            cst = (cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident & cmd_Customer.user == UserAPI.UserName).ListFirst<cmd_Customer>();
                        }
                        else
                        {
                            cst = new cmd_Customer();
                            cst.Process = TaskAPI.Process;
                            cst.Incident = TaskAPI.Incident;
                            cst.UserName = UserAPI.UserName;
                            cst.UserFullName = UserAPI.UserFullName;
                            cst.Time = System.DateTime.Now;
                            cst.Department = UserAPI.Department;
                        }
                        cst.ApplicationNo = ApplicationNo.Text;

                        cst.Status = submit ? (int)ProcessDataState.Normal : (int)ProcessDataState.Draft;

                        cst.Actions = Actions.SelectedValue;
                        cst.DrpPriority = DrpPriority.SelectedValue;
                        cst.Keys = Keys.Items[0].Selected ? "1" : "0";
                        cst.Keys2 = Keys.Items[1].Selected ? "1" : "0";
                        cst.Keys3 = Keys.Items[2].Selected ? "1" : "0";

                        #region Sold To
                        if (Keys.Items[0].Selected)
                        {
                            cst.BA_Customer_Name_In_ZH = BA_Customer_Name_In_ZH.Text;
                            cst.BA_Business_License_No = BA_Business_License_No.Text;
                            cst.BA_SoldTo_Relation = BA_SoldTo_Relation.Text;
                            cst.BA_Customer_Name_In_ZH_1 = BA_Customer_Name_In_ZH_1.Text;
                            cst.BA_Search_Term = BA_Search_Term.Text;
                            cst.BA_Existed_Sold_To_Code = BA_Existed_Sold_To_Code.Text;
                            cst.BA_Block_Existed_Code = BA_Block_Existed_Code.SelectedValue;
                            cst.BA_Language = BA_Language.Text;
                            cst.BA_Country = BA_Country.Text;
                            cst.BA_Time_Zone = BA_Time_Zone.Text;
                            cst.BA_Hierarchy_1 = BA_Hierarchy_1.Text;
                            cst.BA_Hierarchy_2 = BA_Hierarchy_2.SelectedValue;
                            cst.BA_Contact_Person = BA_Contact_Person.Text;
                            cst.BA_Contact_Person_Mobile_Phone = BA_Contact_Person_Mobile_Phone.Text;
                            cst.BA_Contact_Person_SMS = BA_Contact_Person_SMS.Checked ? "1" : "0";
                            cst.BA_Responsible_Man = BA_Responsible_Man.Text;
                            cst.BA_Responsible_Mobile_Phone = BA_Responsible_Mobile_Phone.Text;
                            cst.BA_Responsible_Man_SMS = BA_Responsible_Man_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K1 = BA_Sales_Employee_K1.Text;
                            cst.BA_Sales_Employee_K1_Mobile_Phone = BA_Sales_Employee_K1_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K1_SMS = BA_Sales_Employee_K1_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K1_Employee_Code = BA_Sales_Employee_K1_Employee_Code.Text;
                            cst.BA_Sales_Employee_K2 = BA_Sales_Employee_K2.Text;
                            cst.BA_Sales_Employee_K2_Mobile_Phone = BA_Sales_Employee_K2_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K2_SMS = BA_Sales_Employee_K2_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K2_Employee_Code = BA_Sales_Employee_K2_Employee_Code.Text;
                            cst.BA_Sales_Employee_K3 = BA_Sales_Employee_K3.Text;
                            cst.BA_Sales_Employee_K3_Mobile_Phone = BA_Sales_Employee_K3_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K3_SMS = BA_Sales_Employee_K3_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K3_Employee_Code = BA_Sales_Employee_K3_Employee_Code.Text;
                            cst.BA_Customer_Name_In_EN = BA_Customer_Name_In_EN.Text;
                            cst.BA_Address_In_EN = BA_Address_In_EN.Text;
                            cst.BA_Existed_Sold_To_Code_2 = BA_Existed_Sold_To_Code_2.Text;
                            cst.BA_Existed_Sold_To_Code_Street5 = BA_Existed_Sold_To_Code_Street5.SelectedValue;
                            cst.BA_Existed_Sold_To_Code_City = BA_Existed_Sold_To_Code_City.Text;
                            cst.BA_Existed_Sold_To_Code_District = BA_Existed_Sold_To_Code_District.Text;
                            cst.BA_Existed_Sold_To_Code_Street_4 = BA_Existed_Sold_To_Code_Street_4.Text;
                            cst.BA_Existed_Sold_To_Code_Post_Code = BA_Existed_Sold_To_Code_Post_Code.Text;
                            cst.BA_Existed_Sold_To_Code_Street = BA_Existed_Sold_To_Code_Street.Text;
                            cst.BA_Existed_Sold_To_Code_Contact_Preson = BA_Existed_Sold_To_Code_Contact_Preson.Text;
                            cst.BA_Existed_Sold_To_Code_Tel = BA_Existed_Sold_To_Code_Tel.Text;
                            cst.BA_Existed_Sold_To_Code_Email = BA_Existed_Sold_To_Code_Email.Text;
                            cst.BA_Existed_Bill_To_Code = BA_Existed_Bill_To_Code.Text;
                            cst.BA_Existed_Bill_To_Code_Street5 = BA_Existed_Bill_To_Code_Street5.SelectedValue;
                            cst.BA_Existed_Bill_To_Code_City = BA_Existed_Bill_To_Code_City.Text;
                            cst.BA_Existed_Bill_To_Code_District = BA_Existed_Bill_To_Code_District.Text;
                            cst.BA_Existed_Bill_To_Code_Street_4 = BA_Existed_Bill_To_Code_Street_4.Text;
                            cst.BA_Existed_Bill_To_Code_Post_Code = BA_Existed_Bill_To_Code_Post_Code.Text;
                            cst.BA_Existed_Bill_To_Code_Street = BA_Existed_Bill_To_Code_Street.Text;
                            cst.BA_Existed_Bill_To_Code_Contact_Preson = BA_Existed_Bill_To_Code_Contact_Preson.Text;
                            cst.BA_Existed_Bill_To_Code_Tel = BA_Existed_Bill_To_Code_Tel.Text;
                            cst.BA_Existed_Bill_To_Code_Email = BA_Existed_Bill_To_Code_Email.Text;
                            cst.BA_Existed_Dunn_Recipient_Code = BA_Existed_Dunn_Recipient_Code.Text;
                            cst.BA_Existed_Dunn_Recipient_Street5 = BA_Existed_Dunn_Recipient_Street5.SelectedValue;
                            cst.BA_Existed_Dunn_Recipient_City = BA_Existed_Dunn_Recipient_City.Text;
                            cst.BA_Existed_Dunn_Recipient_District = BA_Existed_Dunn_Recipient_District.Text;
                            cst.BA_Existed_Dunn_Recipient_Street_4 = BA_Existed_Dunn_Recipient_Street_4.Text;
                            cst.BA_Existed_Dunn_Recipient_Post_Code = BA_Existed_Dunn_Recipient_Post_Code.Text;
                            cst.BA_Existed_Dunn_Recipient_Street = BA_Existed_Dunn_Recipient_Street.Text;
                            cst.BA_Existed_Dunn_Recipient_Contact_Preson = BA_Existed_Dunn_Recipient_Contact_Preson.Text;
                            cst.BA_Existed_Dunn_Recipient_Tel = BA_Existed_Dunn_Recipient_Tel.Text;
                            cst.BA_Existed_Dunn_Recipient_Email = BA_Existed_Dunn_Recipient_Email.Text;
                            cst.BA_IsNeedDunn = BA_IsNeedDunn.SelectedValue;
                            cst.BA_Sales_Office = BA_Sales_Office.SelectedValue;
                            cst.BA_Region = BA_Region.SelectedValue;
                            cst.BA_City_Code = BA_City_Code.SelectedValue;
                            cst.BA_County_Code = BA_County_Code.Text;
                            cst.BA_Transportation_Zone = BA_Transportation_Zone.Text;
                            cst.BA_Project_City = BA_Project_City.Text;
                            cst.BA_Industry = BA_Industry.SelectedValue;
                            cst.BA_Industry1 = BA_Industry1.SelectedValue;
                            cst.BA_Industry2 = BA_Industry2.Text;
                            cst.BA_Industry3 = BA_Industry3.Text;
                            cst.SA_Sales_Org = SA_Sales_Org.Text;
                            cst.SA_Sales_Office = SA_Sales_Office.Text;
                            cst.SA_Distribution_Channel = SA_Distribution_Channel.Text;
                            cst.SA_Sales_Employee = SA_Sales_Employee.Text;
                            cst.SA_Sales_Employee_Code = SA_Sales_Employee_Code.Text;
                            cst.SA_Customer_Division_K1 = SA_Customer_Division_K1.Checked ? "1" : "0";
                            cst.SA_Customer_Division_K2 = SA_Customer_Division_K2.Checked ? "1" : "0";
                            cst.SA_Customer_Division_K3 = SA_Customer_Division_K3.Checked ? "1" : "0";
                            cst.SA_Price_Group_1 = SA_Price_Group_1.SelectedValue;
                            cst.SA_Price_Group_2 = SA_Price_Group_2.SelectedValue;
                            cst.SA_Price_Group_3 = SA_Price_Group_3.SelectedValue;
                            cst.SA_Sales_Group_1 = SA_Sales_Group_1.Text;
                            cst.SA_Sales_Group_2 = SA_Sales_Group_2.SelectedValue;
                            cst.SA_Sales_Group_3 = SA_Sales_Group_3.Text;
                            cst.Is_Sales_Null = Is_Sales_Null.Text;
                            cst.Is_K02_Null = Is_K02_Null.Text;
                            cst.IsRSM_Ship = IsRSM_Ship.Text;
                            cst.SA_APO_Customer_Group_APO_K1 = SA_APO_Customer_Group_APO_K1.Text;
                            cst.SA_APO_Customer_Group_APO_K2 = SA_APO_Customer_Group_APO_K2.Text;
                            cst.SA_APO_Customer_Group_APO_K3 = SA_APO_Customer_Group_APO_K3.Text;
                            cst.SA_Partial_Delivery_Per_Item_1 = SA_Partial_Delivery_Per_Item_1.Text;
                            cst.SA_Partial_Delivery_Per_Item_2 = SA_Partial_Delivery_Per_Item_2.Text;
                            cst.SA_Partial_Delivery_Per_Item_3 = SA_Partial_Delivery_Per_Item_3.Text;
                            cst.SA_Max_Partial_Deliveries_1 = SA_Max_Partial_Deliveries_1.Text;
                            cst.SA_Max_Partial_Deliveries_2 = SA_Max_Partial_Deliveries_2.Text;
                            cst.SA_Max_Partial_Deliveries_3 = SA_Max_Partial_Deliveries_3.Text;
                            cst.SA_Switch_Off_Rounding = SA_Switch_Off_Rounding.Checked ? "1" : "0";
                            cst.SA_Relevant_For_POD = SA_Relevant_For_POD.Checked ? "1" : "0";
                            cst.SA_Delivery_Priority = SA_Delivery_Priority.Text;
                            cst.SA_Delivery_Priority_1 = SA_Delivery_Priority_1.Text;
                            cst.SA_Delivery_Priority_3 = SA_Delivery_Priority_3.Text;
                            cst.SA_Shipping_Condition = SA_Shipping_Condition.Text;
                            cst.SA_Rebate = SA_Rebate.Checked ? "1" : "0";
                            cst.SA_Price_Determin = SA_Price_Determin.Checked ? "1" : "0";
                            cst.SA_Acct_Assgmt_Group = SA_Acct_Assgmt_Group.Text;
                            cst.SA_Tax_Classification = SA_Tax_Classification.Text;
                            cst.SA_Itcoterms = SA_Itcoterms.Text;
                            cst.SA_Terms_Of_Payment = SA_Terms_Of_Payment.Text;
                            cst.SA_Attributes_1 = SA_Attributes_1.SelectedValue;
                            cst.SA_Attributes_2 = SA_Attributes_2.SelectedValue;
                            cst.SA_Attributes_7 = SA_Attributes_7.SelectedValue;
                            cst.SA_Attributes_8 = SA_Attributes_8.Text;
                            cst.SA_Attributes_3 = SA_Attributes_3.SelectedValue;
                            cst.SA_Attributes_4 = SA_Attributes_4.SelectedValue;
                            cst.SA_Account_Type = SA_Account_Type.SelectedValue;
                            cst.SA_Attributes_6 = SA_Attributes_6.SelectedValue;
                            cst.SA_Attributes_9 = SA_Attributes_9.Text;
                            cst.SA_Attributes_10 = SA_Attributes_10.Text; //add by kim.zheng 2016/08/24 
                            cst.SA_No_Trans = SA_No_Trans.Text;
                            cst.SA_Customer_Group_2 = SA_Customer_Group_2.Text;
                            cst.SA_Customer_Group_3 = SA_Customer_Group_3.Text;
                            cst.State_owned_L = State_owned_L.Checked ? "1" : "0";
                            cst.Foreign_Company_L = Foreign_Company_L.Checked ? "1" : "0";
                            cst.AN_IG_L = AN_IG_L.Checked ? "1" : "0";
                            cst.Collective_L = Collective_L.Checked ? "1" : "0";
                            cst.Private_Enterpris_L = Private_Enterpris_L.Checked ? "1" : "0";
                            cst.Other_L = Other_L.Checked ? "1" : "0";
                            cst.SA_Ultimate_Holding_Company = SA_Ultimate_Holding_Company.Text;
                            cst.SA_Paid_In_Capital = SA_Paid_In_Capital.Text;
                            cst.SA_Date_Established_Incorporated = SA_Date_Established_Incorporated.Text;
                            cst.SA_Invoice_Division = SA_Invoice_Division.SelectedValue;
                            cst.SA_Invoice_Type = SA_Invoice_Type.SelectedValue;
                            cst.SA_Attributes5 = SA_Attributes5.SelectedValue;
                            cst.SA_Existed_Fiscal_Address_Code_1 = SA_Existed_Fiscal_Address_Code_1.Text;
                            cst.SA_Invoice_Name = SA_Invoice_Name.Text;
                            cst.SA_Region = SA_Region.SelectedValue;
                            cst.SA_City = SA_City.SelectedValue;
                            cst.SA_Street5 = SA_Street5.Text;
                            cst.SA_City2 = SA_City2.Text;
                            cst.SA_District = SA_District.Text;
                            cst.SA_Street = SA_Street.Text;
                            cst.SA_Tel = SA_Tel.Text;
                            cst.SA_Tax_Code = SA_Tax_Code.Text;
                            cst.SA_Bank_Name = SA_Bank_Name.Text;
                            cst.SA_Account = SA_Account.Text;
                            cst.FI_Recon_Account = FI_Recon_Account.Text;
                            cst.FI_Sort_Key = FI_Sort_Key.Text;
                            cst.FI_Cash_Mgmt_Group = FI_Cash_Mgmt_Group.Text;
                            cst.FI_Dunn_Procrdure = FI_Dunn_Procrdure.Text;
                            cst.FI_Payment_Method = FI_Payment_Method.Text;
                            cst.FI_Account_Clerk = FI_Account_Clerk.Text;
                            cst.FI_Customer_User = FI_Customer_User.Text;
                            cst.FI_Act_Clk_Tel_NO = FI_Act_Clk_Tel_NO.Text;
                            cst.FI_Account_Memo = FI_Account_Memo.Text;
                            cst.OT_Estimated_Volume = OT_Estimated_Volume.Text;
                            cst.OT_Estimated_Amount = OT_Estimated_Amount.Text;
                            cst.OT_Currency = OT_Currency.Text;
                            cst.OT_Remarks_1 = OT_Remarks_1.Text;
                            cst.OT_Remarks_2 = OT_Remarks_2.Text;
                            cst.OT_Remarks_3 = OT_Remarks_3.Text;
                            cst.OT_Remarks_4 = OT_Remarks_4.Text;
                            cst.OT_Remarks_5 = OT_Remarks_5.Text;
                            cst.OT_Remarks_6 = OT_Remarks_6.Text;
                            cst.OT_Remarks_7 = OT_Remarks_7.Text;
                            cst.OT_Security_If_any = OT_Security_If_any.SelectedValue;
                            cst.OT_Credit_Limit_Proposed = OT_Credit_Limit_Proposed.Text;
                            cst.OT_Credit_Limit_Approved = OT_Credit_Limit_Approved.Text;
                            cst.OT_Credit_Terms_Proposed = OT_Credit_Terms_Proposed.Text;
                            cst.OT_Credit_Terms_Approved = OT_Credit_Terms_Approved.Text;
                            cst.cmd_OT_Comment_By_Sales_Department = cmd_OT_Comment_By_Sales_Department.Text;
                            cst.cmd_OT_Comment_By_Credit_Control_Department = cmd_OT_Comment_By_Credit_Control_Department.Text;
                        }
                        #endregion

                        #region Ship To
                        //if (Keys.Items[1].Selected)
                        //{
                        ShipTo1.SaveData(submit);
                        //}


                        #endregion

                        #region Hierarchy
                        if (Keys.Items[2].Selected)
                        {
                            cst.NA_Customer_Name = NA_Customer_Name.Text;
                            cst.NA_Is_Have_Account = NA_Is_Have_Account.SelectedValue;
                            cst.NA_Existed_Code = NA_Existed_Code.Text;
                            cst.NA_Customer_Detailed_Add = NA_Customer_Detailed_Add.Text;
                            cst.NA_Fax_No = NA_Fax_No.Text;
                            cst.NA_Street5 = NA_Street5.SelectedValue;
                            cst.NA_City = NA_City.Text;
                            cst.NA_District = NA_District.Text;
                            cst.NA_Street4 = NA_Street4.Text;
                            cst.NA_Post_Code = NA_Post_Code.Text;
                            cst.NA_Street = NA_Street.Text;
                            cst.NA_Contact_Preson = NA_Contact_Preson.Text;
                            cst.NA_Tel = NA_Tel.Text;
                            cst.NA_Region = NA_Region.SelectedValue;
                            cst.NA_Customer_Division_K1 = NA_Customer_Division_K1.Checked ? "1" : "0";
                            cst.NA_Customer_Division_K2 = NA_Customer_Division_K2.Checked ? "1" : "0";
                            cst.NA_Customer_Division_K3 = NA_Customer_Division_K3.Checked ? "1" : "0";
                            cst.NA_Sales_Office = NA_Sales_Office.Text;
                            cst.NA_Sales_Office_1 = NA_Sales_Office_1.Text;
                        }
                        #endregion

                        Storage.Save(Storage.Context1, cst);
                        #endregion
                    }
                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }



                    #endregion

                    #endregion
                    #region “CA Check”步骤
                    if (TaskAPI.Step == "CA Check")
                    {
                        #region CA Check存值
                        cmd_Customer cst = new cmd_Customer();
                        if ((cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident).Count<cmd_Customer>() > 0)
                        {
                            cst = (cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident).ListFirst<cmd_Customer>();
                        }
                        else
                        {
                            cst = new cmd_Customer();
                            cst.Process = TaskAPI.Process;
                            cst.Incident = TaskAPI.Incident;
                            cst.UserName = UserAPI.UserName;
                            cst.UserFullName = UserAPI.UserFullName;
                            cst.ApplicationNo = ApplicationNo.Text;
                            cst.Time = System.DateTime.Now;
                            cst.Status = 1;
                            cst.Department = UserAPI.Department;
                        }

                        cst.Status = submit ? (int)ProcessDataState.Normal : (int)ProcessDataState.Draft;

                        cst.Actions = Actions.SelectedValue;
                        cst.DrpPriority = DrpPriority.SelectedValue;
                        cst.Keys = Keys.Items[0].Selected ? "1" : "0";
                        cst.Keys2 = Keys.Items[1].Selected ? "1" : "0";
                        cst.Keys3 = Keys.Items[2].Selected ? "1" : "0";

                        #region Sold To
                        if (Keys.Items[0].Selected)
                        {
                            cst.BA_Customer_Name_In_ZH = BA_Customer_Name_In_ZH.Text;
                            cst.BA_Business_License_No = BA_Business_License_No.Text;
                            cst.BA_SoldTo_Relation = BA_SoldTo_Relation.Text;
                            cst.BA_Customer_Name_In_ZH_1 = BA_Customer_Name_In_ZH_1.Text;
                            cst.BA_Search_Term = BA_Search_Term.Text;
                            cst.BA_Existed_Sold_To_Code = BA_Existed_Sold_To_Code.Text;
                            cst.BA_Block_Existed_Code = BA_Block_Existed_Code.SelectedValue;
                            cst.BA_Language = BA_Language.Text;
                            cst.BA_Country = BA_Country.Text;
                            cst.BA_Time_Zone = BA_Time_Zone.Text;
                            cst.BA_Hierarchy_1 = BA_Hierarchy_1.Text;
                            cst.BA_Hierarchy_2 = BA_Hierarchy_2.SelectedValue;
                            cst.BA_Contact_Person = BA_Contact_Person.Text;
                            cst.BA_Contact_Person_Mobile_Phone = BA_Contact_Person_Mobile_Phone.Text;
                            cst.BA_Contact_Person_SMS = BA_Contact_Person_SMS.Checked ? "1" : "0";
                            cst.BA_Responsible_Man = BA_Responsible_Man.Text;
                            cst.BA_Responsible_Mobile_Phone = BA_Responsible_Mobile_Phone.Text;
                            cst.BA_Responsible_Man_SMS = BA_Responsible_Man_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K1 = BA_Sales_Employee_K1.Text;
                            cst.BA_Sales_Employee_K1_Mobile_Phone = BA_Sales_Employee_K1_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K1_SMS = BA_Sales_Employee_K1_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K1_Employee_Code = BA_Sales_Employee_K1_Employee_Code.Text;
                            cst.BA_Sales_Employee_K2 = BA_Sales_Employee_K2.Text;
                            cst.BA_Sales_Employee_K2_Mobile_Phone = BA_Sales_Employee_K2_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K2_SMS = BA_Sales_Employee_K2_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K2_Employee_Code = BA_Sales_Employee_K2_Employee_Code.Text;
                            cst.BA_Sales_Employee_K3 = BA_Sales_Employee_K3.Text;
                            cst.BA_Sales_Employee_K3_Mobile_Phone = BA_Sales_Employee_K3_Mobile_Phone.Text;
                            cst.BA_Sales_Employee_K3_SMS = BA_Sales_Employee_K3_SMS.Checked ? "1" : "0";
                            cst.BA_Sales_Employee_K3_Employee_Code = BA_Sales_Employee_K3_Employee_Code.Text;
                            cst.BA_Customer_Name_In_EN = BA_Customer_Name_In_EN.Text;
                            cst.BA_Address_In_EN = BA_Address_In_EN.Text;
                            cst.BA_Existed_Sold_To_Code_2 = BA_Existed_Sold_To_Code_2.Text;
                            cst.BA_Existed_Sold_To_Code_Street5 = BA_Existed_Sold_To_Code_Street5.SelectedValue;
                            cst.BA_Existed_Sold_To_Code_City = BA_Existed_Sold_To_Code_City.Text;
                            cst.BA_Existed_Sold_To_Code_District = BA_Existed_Sold_To_Code_District.Text;
                            cst.BA_Existed_Sold_To_Code_Street_4 = BA_Existed_Sold_To_Code_Street_4.Text;
                            cst.BA_Existed_Sold_To_Code_Post_Code = BA_Existed_Sold_To_Code_Post_Code.Text;
                            cst.BA_Existed_Sold_To_Code_Street = BA_Existed_Sold_To_Code_Street.Text;
                            cst.BA_Existed_Sold_To_Code_Contact_Preson = BA_Existed_Sold_To_Code_Contact_Preson.Text;
                            cst.BA_Existed_Sold_To_Code_Tel = BA_Existed_Sold_To_Code_Tel.Text;
                            cst.BA_Existed_Sold_To_Code_Email = BA_Existed_Sold_To_Code_Email.Text;
                            cst.BA_Existed_Bill_To_Code = BA_Existed_Bill_To_Code.Text;
                            cst.BA_Existed_Bill_To_Code_Street5 = BA_Existed_Bill_To_Code_Street5.SelectedValue;
                            cst.BA_Existed_Bill_To_Code_City = BA_Existed_Bill_To_Code_City.Text;
                            cst.BA_Existed_Bill_To_Code_District = BA_Existed_Bill_To_Code_District.Text;
                            cst.BA_Existed_Bill_To_Code_Street_4 = BA_Existed_Bill_To_Code_Street_4.Text;
                            cst.BA_Existed_Bill_To_Code_Post_Code = BA_Existed_Bill_To_Code_Post_Code.Text;
                            cst.BA_Existed_Bill_To_Code_Street = BA_Existed_Bill_To_Code_Street.Text;
                            cst.BA_Existed_Bill_To_Code_Contact_Preson = BA_Existed_Bill_To_Code_Contact_Preson.Text;
                            cst.BA_Existed_Bill_To_Code_Tel = BA_Existed_Bill_To_Code_Tel.Text;
                            cst.BA_Existed_Bill_To_Code_Email = BA_Existed_Bill_To_Code_Email.Text;
                            cst.BA_Existed_Dunn_Recipient_Code = BA_Existed_Dunn_Recipient_Code.Text;
                            cst.BA_Existed_Dunn_Recipient_Street5 = BA_Existed_Dunn_Recipient_Street5.SelectedValue;
                            cst.BA_Existed_Dunn_Recipient_City = BA_Existed_Dunn_Recipient_City.Text;
                            cst.BA_Existed_Dunn_Recipient_District = BA_Existed_Dunn_Recipient_District.Text;
                            cst.BA_Existed_Dunn_Recipient_Street_4 = BA_Existed_Dunn_Recipient_Street_4.Text;
                            cst.BA_Existed_Dunn_Recipient_Post_Code = BA_Existed_Dunn_Recipient_Post_Code.Text;
                            cst.BA_Existed_Dunn_Recipient_Street = BA_Existed_Dunn_Recipient_Street.Text;
                            cst.BA_Existed_Dunn_Recipient_Contact_Preson = BA_Existed_Dunn_Recipient_Contact_Preson.Text;
                            cst.BA_Existed_Dunn_Recipient_Tel = BA_Existed_Dunn_Recipient_Tel.Text;
                            cst.BA_Existed_Dunn_Recipient_Email = BA_Existed_Dunn_Recipient_Email.Text;
                            cst.BA_IsNeedDunn = BA_IsNeedDunn.SelectedValue;
                            cst.BA_Sales_Office = BA_Sales_Office.SelectedValue;
                            cst.BA_Region = BA_Region.SelectedValue;
                            cst.BA_City_Code = BA_City_Code.SelectedValue;
                            cst.BA_County_Code = BA_County_Code.Text;
                            cst.BA_Transportation_Zone = BA_Transportation_Zone.Text;
                            cst.BA_Project_City = BA_Project_City.Text;
                            cst.BA_Industry = BA_Industry.SelectedValue;
                            cst.BA_Industry1 = BA_Industry1.SelectedValue;
                            cst.BA_Industry2 = BA_Industry2.Text;
                            cst.BA_Industry3 = BA_Industry3.Text;
                            cst.SA_Sales_Org = SA_Sales_Org.Text;
                            cst.SA_Sales_Office = SA_Sales_Office.Text;
                            cst.SA_Distribution_Channel = SA_Distribution_Channel.Text;
                            cst.SA_Sales_Employee = SA_Sales_Employee.Text;
                            cst.SA_Sales_Employee_Code = SA_Sales_Employee_Code.Text;
                            cst.SA_Customer_Division_K1 = SA_Customer_Division_K1.Checked ? "1" : "0";
                            cst.SA_Customer_Division_K2 = SA_Customer_Division_K2.Checked ? "1" : "0";
                            cst.SA_Customer_Division_K3 = SA_Customer_Division_K3.Checked ? "1" : "0";
                            cst.SA_Price_Group_1 = SA_Price_Group_1.SelectedValue;
                            cst.SA_Price_Group_2 = SA_Price_Group_2.SelectedValue;
                            cst.SA_Price_Group_3 = SA_Price_Group_3.SelectedValue;
                            cst.SA_Sales_Group_1 = SA_Sales_Group_1.Text;
                            cst.SA_Sales_Group_2 = SA_Sales_Group_2.SelectedValue;
                            cst.SA_Sales_Group_3 = SA_Sales_Group_3.Text;
                            cst.Is_Sales_Null = Is_Sales_Null.Text;
                            cst.Is_K02_Null = Is_K02_Null.Text;
                            cst.IsRSM_Ship = IsRSM_Ship.Text;
                            cst.SA_APO_Customer_Group_APO_K1 = SA_APO_Customer_Group_APO_K1.Text;
                            cst.SA_APO_Customer_Group_APO_K2 = SA_APO_Customer_Group_APO_K2.Text;
                            cst.SA_APO_Customer_Group_APO_K3 = SA_APO_Customer_Group_APO_K3.Text;
                            cst.SA_Partial_Delivery_Per_Item_1 = SA_Partial_Delivery_Per_Item_1.Text;
                            cst.SA_Partial_Delivery_Per_Item_2 = SA_Partial_Delivery_Per_Item_2.Text;
                            cst.SA_Partial_Delivery_Per_Item_3 = SA_Partial_Delivery_Per_Item_3.Text;
                            cst.SA_Max_Partial_Deliveries_1 = SA_Max_Partial_Deliveries_1.Text;
                            cst.SA_Max_Partial_Deliveries_2 = SA_Max_Partial_Deliveries_2.Text;
                            cst.SA_Max_Partial_Deliveries_3 = SA_Max_Partial_Deliveries_3.Text;
                            cst.SA_Switch_Off_Rounding = SA_Switch_Off_Rounding.Checked ? "1" : "0";
                            cst.SA_Relevant_For_POD = SA_Relevant_For_POD.Checked ? "1" : "0";
                            cst.SA_Delivery_Priority = SA_Delivery_Priority.Text;
                            cst.SA_Delivery_Priority_1 = SA_Delivery_Priority_1.Text;
                            cst.SA_Delivery_Priority_3 = SA_Delivery_Priority_3.Text;
                            cst.SA_Shipping_Condition = SA_Shipping_Condition.Text;
                            cst.SA_Rebate = SA_Rebate.Checked ? "1" : "0";
                            cst.SA_Price_Determin = SA_Price_Determin.Checked ? "1" : "0";
                            cst.SA_Acct_Assgmt_Group = SA_Acct_Assgmt_Group.Text;
                            cst.SA_Tax_Classification = SA_Tax_Classification.Text;
                            cst.SA_Itcoterms = SA_Itcoterms.Text;
                            cst.SA_Terms_Of_Payment = SA_Terms_Of_Payment.Text;
                            cst.SA_Attributes_1 = SA_Attributes_1.SelectedValue;
                            cst.SA_Attributes_2 = SA_Attributes_2.SelectedValue;
                            cst.SA_Attributes_7 = SA_Attributes_7.SelectedValue;
                            cst.SA_Attributes_8 = SA_Attributes_8.Text;
                            cst.SA_Attributes_3 = SA_Attributes_3.SelectedValue;
                            cst.SA_Attributes_4 = SA_Attributes_4.SelectedValue;
                            cst.SA_Account_Type = SA_Account_Type.SelectedValue;
                            cst.SA_Attributes_6 = SA_Attributes_6.SelectedValue;
                            cst.SA_Attributes_9 = SA_Attributes_9.Text;
                            cst.SA_Attributes_10 = SA_Attributes_10.Text;
                            cst.SA_No_Trans = SA_No_Trans.Text;
                            cst.SA_Customer_Group_2 = SA_Customer_Group_2.Text;
                            cst.SA_Customer_Group_3 = SA_Customer_Group_3.Text;
                            cst.State_owned_L = State_owned_L.Checked ? "1" : "0";
                            cst.Foreign_Company_L = Foreign_Company_L.Checked ? "1" : "0";
                            cst.AN_IG_L = AN_IG_L.Checked ? "1" : "0";
                            cst.Collective_L = Collective_L.Checked ? "1" : "0";
                            cst.Private_Enterpris_L = Private_Enterpris_L.Checked ? "1" : "0";
                            cst.Other_L = Other_L.Checked ? "1" : "0";
                            cst.SA_Ultimate_Holding_Company = SA_Ultimate_Holding_Company.Text;
                            cst.SA_Paid_In_Capital = SA_Paid_In_Capital.Text;
                            cst.SA_Date_Established_Incorporated = SA_Date_Established_Incorporated.Text;
                            cst.SA_Invoice_Division = SA_Invoice_Division.SelectedValue;
                            cst.SA_Invoice_Type = SA_Invoice_Type.SelectedValue;
                            cst.SA_Attributes5 = SA_Attributes5.SelectedValue;
                            cst.SA_Existed_Fiscal_Address_Code_1 = SA_Existed_Fiscal_Address_Code_1.Text;
                            cst.SA_Invoice_Name = SA_Invoice_Name.Text;
                            cst.SA_Region = SA_Region.SelectedValue;
                            cst.SA_City = SA_City.SelectedValue;
                            cst.SA_Street5 = SA_Street5.Text;
                            cst.SA_City2 = SA_City2.Text;
                            cst.SA_District = SA_District.Text;
                            cst.SA_Street = SA_Street.Text;
                            cst.SA_Tel = SA_Tel.Text;
                            cst.SA_Tax_Code = SA_Tax_Code.Text;
                            cst.SA_Bank_Name = SA_Bank_Name.Text;
                            cst.SA_Account = SA_Account.Text;
                            cst.FI_Recon_Account = FI_Recon_Account.Text;
                            cst.FI_Sort_Key = FI_Sort_Key.Text;
                            cst.FI_Cash_Mgmt_Group = FI_Cash_Mgmt_Group.Text;
                            cst.FI_Dunn_Procrdure = FI_Dunn_Procrdure.Text;
                            cst.FI_Payment_Method = FI_Payment_Method.Text;
                            cst.FI_Account_Clerk = FI_Account_Clerk.Text;
                            cst.FI_Customer_User = FI_Customer_User.Text;
                            cst.FI_Act_Clk_Tel_NO = FI_Act_Clk_Tel_NO.Text;
                            cst.FI_Account_Memo = FI_Account_Memo.Text;
                            cst.OT_Estimated_Volume = OT_Estimated_Volume.Text;
                            cst.OT_Estimated_Amount = OT_Estimated_Amount.Text;
                            cst.OT_Currency = OT_Currency.Text;
                            cst.OT_Remarks_1 = OT_Remarks_1.Text;
                            cst.OT_Remarks_2 = OT_Remarks_2.Text;
                            cst.OT_Remarks_3 = OT_Remarks_3.Text;
                            cst.OT_Remarks_4 = OT_Remarks_4.Text;
                            cst.OT_Remarks_5 = OT_Remarks_5.Text;
                            cst.OT_Remarks_6 = OT_Remarks_6.Text;
                            cst.OT_Remarks_7 = OT_Remarks_7.Text;
                            cst.OT_Security_If_any = OT_Security_If_any.SelectedValue;
                            cst.OT_Credit_Limit_Proposed = OT_Credit_Limit_Proposed.Text;
                            cst.OT_Credit_Limit_Approved = OT_Credit_Limit_Approved.Text;
                            cst.OT_Credit_Terms_Proposed = OT_Credit_Terms_Proposed.Text;
                            cst.OT_Credit_Terms_Approved = OT_Credit_Terms_Approved.Text;
                            cst.cmd_OT_Comment_By_Sales_Department = cmd_OT_Comment_By_Sales_Department.Text;
                            cst.cmd_OT_Comment_By_Credit_Control_Department = cmd_OT_Comment_By_Credit_Control_Department.Text;
                        }
                        #endregion

                        #region Ship To
                        //if (Keys.Items[1].Selected)
                        //{
                        ShipTo1.SaveData(false);
                        //}


                        #endregion

                        #region Hierarchy
                        if (Keys.Items[2].Selected)
                        {
                            cst.NA_Customer_Name = NA_Customer_Name.Text;
                            cst.NA_Is_Have_Account = NA_Is_Have_Account.SelectedValue;
                            cst.NA_Existed_Code = NA_Existed_Code.Text;
                            cst.NA_Customer_Detailed_Add = NA_Customer_Detailed_Add.Text;
                            cst.NA_Fax_No = NA_Fax_No.Text;
                            cst.NA_Street5 = NA_Street5.SelectedValue;
                            cst.NA_City = NA_City.Text;
                            cst.NA_District = NA_District.Text;
                            cst.NA_Street4 = NA_Street4.Text;
                            cst.NA_Post_Code = NA_Post_Code.Text;
                            cst.NA_Street = NA_Street.Text;
                            cst.NA_Contact_Preson = NA_Contact_Preson.Text;
                            cst.NA_Tel = NA_Tel.Text;
                            cst.NA_Region = NA_Region.SelectedValue;
                            cst.NA_Customer_Division_K1 = NA_Customer_Division_K1.Checked ? "1" : "0";
                            cst.NA_Customer_Division_K2 = NA_Customer_Division_K2.Checked ? "1" : "0";
                            cst.NA_Customer_Division_K3 = NA_Customer_Division_K3.Checked ? "1" : "0";
                            cst.NA_Sales_Office = NA_Sales_Office.Text;
                            cst.NA_Sales_Office_1 = NA_Sales_Office_1.Text;
                        }
                        #endregion

                        Storage.Save(Storage.Context1, cst);
                        #endregion
                        #region Priority功能
                        if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                        {
                            mdc_Priority pro;
                            if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                            {
                                pro = new mdc_Priority();
                                pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                                pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                                Storage.Save(pro);
                            }
                            else
                            {
                                pro = new mdc_Priority();
                                pro.Process = TaskAPI.Process;
                                pro.Incident = TaskAPI.Incident;
                                pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                                Storage.Save(pro);
                            }

                        }



                        #endregion

                    }
                    #endregion
                    #region “DMO Maintain”步骤
                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }

                    if (TaskAPI.Step == "DMO Maintain")
                    {
                        (cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident).Edit<cmd_Customer>(p =>
                        {
                            p.SAP_Code = SAP_Code.Text;
                            p.Status = submit ? (int)ProcessDataState.Normal : (int)ProcessDataState.Draft;
                        }
                        );
                    }

                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident).Edit<cmd_Customer>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_CheckList = DMO_CheckList.Checked ? "1" : "0";
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;
                            p.DMO_Arrpvoe_Creation_Number = DMO_Arrpvoe_Creation_Number.Text;
                            p.DMO_Arrpvoe_Creation_Time = DMO_Arrpvoe_Creation_Time.Text;
                            p.DMO_Maintain_Creation_Number = DMO_Maintain_Creation_Number.Text;
                            p.DMO_Maintain_Creation_Time = DMO_Maintain_Creation_Time.Text;
                            p.DMO_Check_Creation_Number = DMO_Check_Creation_Number.Text;
                            p.DMO_Check_Creation_Time = DMO_Check_Creation_Time.Text;
                            p.DMO_Arrpvoe_Revision_Number = DMO_Arrpvoe_Revision_Number.Text;
                            p.DMO_Arrpvoe_Revision_Time = DMO_Arrpvoe_Revision_Time.Text;
                            p.DMO_Maintain_Revision_Number = DMO_Maintain_Revision_Number.Text;
                            p.DMO_Maintain_Revision_Time = DMO_Maintain_Revision_Time.Text;
                            p.DMO_Check_Revision_Number = DMO_Check_Revision_Number.Text;
                            p.DMO_Check_Revision_Time = DMO_Check_Revision_Time.Text;

                            //p.DMO_SalesSAP_Code = DMO_SalesSAP_Code.Text;
                        }
                        );
                    }
                    #endregion

                    var assessment = Assessment1.Assessment;

                    //删除之前的暂存Assessment
                    assessment.Status = submit ? (int)ProcessDataState.Normal : (int)ProcessDataState.Draft;
                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == TaskAPI.Incident &
                        t_Assessment.step == TaskAPI.Step &
                     (t_Assessment.userName == UserAPI.UserName | t_Assessment.assignedToUserName == UserAPI.UserName) & t_Assessment.status == (int)ProcessDataState.Draft).
                        Delete<t_Assessment>();
                    Storage.Save(assessment);
                });

                if (submit)
                {
                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }

                    Assessment1.SubmitTo();
                    TaskAPI.Send();

                    //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                    if (TaskAPI.IsInitiate)
                    {

                        if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                        {
                            (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                            {
                                p.Incident = TaskAPI.Incident;
                            });
                        }
                        (cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == 0 & cmd_Customer.user == (TaskAPI.IsInitiate ? UserAPI.UserName : TaskAPI.UserName)).Edit<cmd_Customer>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        (cmd_ShipTo.process == TaskAPI.Process & cmd_ShipTo.incident == 0 & cmd_ShipTo.user == (TaskAPI.IsInitiate ? UserAPI.UserName : TaskAPI.UserName)).Edit<cmd_ShipTo>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == (TaskAPI.IsInitiate ? UserAPI.UserName : TaskAPI.UserName)).Edit<t_Assessment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == (TaskAPI.IsInitiate ? UserAPI.UserName : TaskAPI.UserName)).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }

                    Send.Visible = false;

                    StoreAPI.ClearKey(TaskID);
                }

                #endregion
                Anthem.Manager.AddScriptForClientSideEval(string.Format("JSInfomation('{0}',{1})", submit ? Resources.Global.C_00_Success : Resources.Global.C_00_SaveSuccess, submit ? "true" : "false"));

                if (!submit)
                {
                    LoadData("LoadDraft");
                    ShipTo1.LoadData("LoadDraft");
                }

            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用CMD方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }

        public bool IsDraftExisted
        {
            get
            {
                var exp = cmd_Customer.process == TaskAPI.Process & cmd_Customer.incident == TaskAPI.Incident &
                          cmd_Customer.status == (int)ProcessDataState.Draft;
                if (TaskAPI.IsBeginStep)
                    exp &= cmd_Customer.user == UserAPI.UserName;
                return exp.Count<cmd_Customer>() > 0;
            }
        }

        public bool DraftExistAndLoadDraft { get; private set; }
        public void LoadData(string act)
        {
            bool flg = ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit) ? true : false;

            #region 发起步骤
            if ((TaskAPI.IsBeginStep || TaskAPI.Step == "CA Check") && TaskAPI.IsAllowSubmit)
            {
                //InitDropDownList(); 魏军修改
                SetColor();
            }
            InitDropDownList();
            #endregion


            var action = string.IsNullOrEmpty(act) ? Request.QueryString["Action"] : act;

            if (IsDraftExisted)
            {
                var script = @"
                                var r=confirm('系统检测到您之前保存了草稿，是否加载草稿？')
                                if (r==true)
                                  {
                                           window.location.href='" + Request.Url + @"&Action=LoadDraft';
                                  }
                                else
                                  {
                                            window.location.href='" + Request.Url + @"&Action=IgnoreDraft';
                                  }
                                ";
                if (!TaskAPI.IsInitiate && TaskAPI.IsAllowSubmit)
                {
                    DraftExistAndLoadDraft = true;
                }
                else
                {
                    if (string.IsNullOrEmpty(action))
                    {
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "", script, true);
                    }
                    else if (action == "LoadDraft")
                    {
                        DraftExistAndLoadDraft = true;
                    }

                }
            }

            #region 审批环节

            cmd_Customer cst = DraftExistAndLoadDraft
                                   ? (TaskAPI.IsBeginStep
                                          ? (cmd_Customer.process == TaskAPI.Process &
                                             cmd_Customer.incident == TaskAPI.Incident &
                                             cmd_Customer.user == UserAPI.UserName &
                                             cmd_Customer.status == (int)ProcessDataState.Draft).ListFirst
                                                <cmd_Customer>()
                                          : (cmd_Customer.process == TaskAPI.Process &
                                             cmd_Customer.incident == TaskAPI.Incident &
                                             cmd_Customer.status == (int)ProcessDataState.Draft).ListFirst
                                                <cmd_Customer>())
                                   : (cmd_Customer.process == TaskAPI.Process &
                                      cmd_Customer.incident == TaskAPI.Incident &
                                      cmd_Customer.status == 1).ListFirst<cmd_Customer>();
            if (!TaskAPI.IsInitiate || DraftExistAndLoadDraft)
            {
                #region 加载数据并显示
                if (cst != null)
                {
                    //Actions.SelectedValue                       = cst.Actions;
                    SetDropDownListValue(Actions, cst.Actions);
                    Keys.Items[0].Selected = cst.Keys == "1";
                    Keys.Items[1].Selected = cst.Keys2 == "1";
                    Keys.Items[2].Selected = cst.Keys3 == "1";
                    SetDropDownListValue(DrpPriority, cst.DrpPriority);
                    if (Actions.SelectedValue == "1")
                    {
                        BA_Existed_Sold_To_Code.Visible = false;
                        BA_Existed_Sold_To_Code_L.Visible = false;

                        SA_No_Trans_L.Visible = false;
                        SA_No_Trans.Visible = false;

                        NA_Existed_Code.Visible = false;
                        NA_Existed_Code_L.Visible = false;
                    }

                    if (Actions.SelectedValue == "4")
                    {
                        SA_No_Trans_L.Visible = true;
                        SA_No_Trans.Visible = true;
                    }
                    else
                    {
                        SA_No_Trans_L.Visible = false;
                        SA_No_Trans.Visible = false;
                    }

                    if (Actions.SelectedValue != "1")
                    {
                        ShipTo1.ST_Total_ST_L.Visible = false;
                        ShipTo1.ST_Total_ST.Visible = false;
                        ShipTo1.ST_Des_Total.Visible = false;
                    }



                    if (Keys.Items[1].Selected && Keys.Items[0].Selected && Actions.SelectedValue == "1")
                    {
                        ShipTo1.ST_Sold_To_No.Enabled = false;
                    }

                    else
                    {
                        ShipTo1.ST_Sold_To_No.Enabled = true;
                    }

                    if (Keys.Items[1].Selected && !Keys.Items[0].Selected && Actions.SelectedValue == "1")
                    {
                        ShipTo1.ST_Total_ST.Visible = true;
                        ShipTo1.ST_Total_ST_L.Visible = true;
                        ShipTo1.ST_Des_Total.Visible = true;
                    }
                    else
                    {
                        ShipTo1.ST_Total_ST.Visible = false;
                        ShipTo1.ST_Total_ST_L.Visible = false;
                        ShipTo1.ST_Des_Total.Visible = false;
                    }


                    SetColor();
                    ApplicationNo.Text = cst.ApplicationNo;


                    BA_Customer_Name_In_ZH.Text = cst.BA_Customer_Name_In_ZH;
                    BA_Business_License_No.Text = cst.BA_Business_License_No;
                    BA_SoldTo_Relation.Text = cst.BA_SoldTo_Relation;
                    BA_Customer_Name_In_ZH_1.Text = cst.BA_Customer_Name_In_ZH_1;
                    BA_Search_Term.Text = cst.BA_Search_Term;
                    BA_Existed_Sold_To_Code.Text = cst.BA_Existed_Sold_To_Code;
                    // BA_Block_Existed_Code.SelectedValue                = cst.BA_Block_Existed_Code;
                    SetDropDownListValue(BA_Block_Existed_Code, cst.BA_Block_Existed_Code);
                    BA_Language.Text = cst.BA_Language;
                    BA_Country.Text = cst.BA_Country;
                    BA_Time_Zone.Text = cst.BA_Time_Zone;
                    BA_Hierarchy_1.Text = cst.BA_Hierarchy_1;

                    SetDropDownListValue(BA_Hierarchy_2, cst.BA_Hierarchy_2);
                    if (flg)
                    {
                        BA_Hierarchy_2_SelectedIndexChanged(null, EventArgs.Empty);
                    }

                    BA_Contact_Person.Text = cst.BA_Contact_Person;
                    BA_Contact_Person_Mobile_Phone.Text = cst.BA_Contact_Person_Mobile_Phone;
                    BA_Contact_Person_SMS.Checked = cst.BA_Contact_Person_SMS == "1";
                    BA_Responsible_Man.Text = cst.BA_Responsible_Man;
                    BA_Responsible_Mobile_Phone.Text = cst.BA_Responsible_Mobile_Phone;
                    BA_Responsible_Man_SMS.Checked = cst.BA_Responsible_Man_SMS == "1";
                    BA_Sales_Employee_K1.Text = cst.BA_Sales_Employee_K1;
                    BA_Sales_Employee_K1_Mobile_Phone.Text = cst.BA_Sales_Employee_K1_Mobile_Phone;
                    BA_Sales_Employee_K1_SMS.Checked = cst.BA_Sales_Employee_K1_SMS == "1";
                    BA_Sales_Employee_K1_Employee_Code.Text = cst.BA_Sales_Employee_K1_Employee_Code;
                    BA_Sales_Employee_K2.Text = cst.BA_Sales_Employee_K2;
                    BA_Sales_Employee_K2_Mobile_Phone.Text = cst.BA_Sales_Employee_K2_Mobile_Phone;
                    BA_Sales_Employee_K2_SMS.Checked = cst.BA_Sales_Employee_K2_SMS == "1";
                    BA_Sales_Employee_K2_Employee_Code.Text = cst.BA_Sales_Employee_K2_Employee_Code;
                    BA_Sales_Employee_K3.Text = cst.BA_Sales_Employee_K3;
                    BA_Sales_Employee_K3_Mobile_Phone.Text = cst.BA_Sales_Employee_K3_Mobile_Phone;
                    BA_Sales_Employee_K3_SMS.Checked = cst.BA_Sales_Employee_K3_SMS == "1";
                    BA_Sales_Employee_K3_Employee_Code.Text = cst.BA_Sales_Employee_K3_Employee_Code;
                    BA_Customer_Name_In_EN.Text = cst.BA_Customer_Name_In_EN;
                    BA_Address_In_EN.Text = cst.BA_Address_In_EN;
                    BA_Existed_Sold_To_Code_2.Text = cst.BA_Existed_Sold_To_Code_2;
                    SetDropDownListValue(BA_Existed_Sold_To_Code_Street5, cst.BA_Existed_Sold_To_Code_Street5);
                    if (flg)
                    {
                        BA_Existed_Sold_To_Code_Street5_SelectedIndexChanged(null, EventArgs.Empty);
                    }

                    BA_Existed_Sold_To_Code_City.Text = cst.BA_Existed_Sold_To_Code_City;
                    BA_Existed_Sold_To_Code_District.Text = cst.BA_Existed_Sold_To_Code_District;
                    BA_Existed_Sold_To_Code_Street_4.Text = cst.BA_Existed_Sold_To_Code_Street_4;
                    BA_Existed_Sold_To_Code_Post_Code.Text = cst.BA_Existed_Sold_To_Code_Post_Code;
                    BA_Existed_Sold_To_Code_Street.Text = cst.BA_Existed_Sold_To_Code_Street;
                    BA_Existed_Sold_To_Code_Contact_Preson.Text = cst.BA_Existed_Sold_To_Code_Contact_Preson;
                    BA_Existed_Sold_To_Code_Tel.Text = cst.BA_Existed_Sold_To_Code_Tel;
                    BA_Existed_Sold_To_Code_Email.Text = cst.BA_Existed_Sold_To_Code_Email;
                    BA_Existed_Bill_To_Code.Text = cst.BA_Existed_Bill_To_Code;
                    SetDropDownListValue(BA_Existed_Bill_To_Code_Street5, cst.BA_Existed_Bill_To_Code_Street5);
                    if (flg)
                    {
                        BA_Existed_Bill_To_Code_TextChanged(null, EventArgs.Empty);
                    }
                    BA_Existed_Bill_To_Code_City.Text = cst.BA_Existed_Bill_To_Code_City;
                    BA_Existed_Bill_To_Code_District.Text = cst.BA_Existed_Bill_To_Code_District;
                    BA_Existed_Bill_To_Code_Street_4.Text = cst.BA_Existed_Bill_To_Code_Street_4;
                    BA_Existed_Bill_To_Code_Post_Code.Text = cst.BA_Existed_Bill_To_Code_Post_Code;
                    BA_Existed_Bill_To_Code_Street.Text = cst.BA_Existed_Bill_To_Code_Street;
                    BA_Existed_Bill_To_Code_Contact_Preson.Text = cst.BA_Existed_Bill_To_Code_Contact_Preson;
                    BA_Existed_Bill_To_Code_Tel.Text = cst.BA_Existed_Bill_To_Code_Tel;
                    BA_Existed_Bill_To_Code_Email.Text = cst.BA_Existed_Bill_To_Code_Email;
                    BA_Existed_Dunn_Recipient_Code.Text = cst.BA_Existed_Dunn_Recipient_Code;
                    SetDropDownListValue(BA_Existed_Dunn_Recipient_Street5, cst.BA_Existed_Dunn_Recipient_Street5);
                    if (flg)
                    {
                        BA_Existed_Dunn_Recipient_Street5_SelectedIndexChanged(null, EventArgs.Empty);
                    }
                    BA_Existed_Dunn_Recipient_City.Text = cst.BA_Existed_Dunn_Recipient_City;
                    BA_Existed_Dunn_Recipient_District.Text = cst.BA_Existed_Dunn_Recipient_District;
                    BA_Existed_Dunn_Recipient_Street_4.Text = cst.BA_Existed_Dunn_Recipient_Street_4;
                    BA_Existed_Dunn_Recipient_Post_Code.Text = cst.BA_Existed_Dunn_Recipient_Post_Code;
                    BA_Existed_Dunn_Recipient_Street.Text = cst.BA_Existed_Dunn_Recipient_Street;
                    BA_Existed_Dunn_Recipient_Contact_Preson.Text = cst.BA_Existed_Dunn_Recipient_Contact_Preson;
                    BA_Existed_Dunn_Recipient_Tel.Text = cst.BA_Existed_Dunn_Recipient_Tel;
                    BA_Existed_Dunn_Recipient_Email.Text = cst.BA_Existed_Dunn_Recipient_Email;
                    //BA_IsNeedDunn.SelectedValue                 = cst.BA_IsNeedDunn;
                    SetDropDownListValue(BA_IsNeedDunn, cst.BA_IsNeedDunn);
                    SetDropDownListValue(BA_Sales_Office, cst.BA_Sales_Office);

                    BA_Sales_Office_SelectedIndexChanged1(null, null);


                    SetDropDownListValue(BA_Region, cst.BA_Region);

                    BA_Region_SelectedIndexChanged(null, null);


                    SetDropDownListValue(BA_City_Code, cst.BA_City_Code);
                    if (flg)
                    {
                        BA_County_Code_TextChanged(null, null);
                    }



                    //if (!flg)
                    //    BA_City_Code.SelectedValue = cst.BA_City_Code;
                    //else
                    //{
                    //    BA_Region.SelectedIndexChanged -= BA_Region_SelectedIndexChanged;
                    //    BA_Region.SelectedIndexChanged += BA_Region_SelectedIndexChanged;
                    //    SetDropDownListValue(BA_City_Code, cst.BA_City_Code);
                    //}

                    BA_County_Code.Text = cst.BA_County_Code;
                    BA_Transportation_Zone.Text = cst.BA_Transportation_Zone;
                    BA_Project_City.Text = cst.BA_Project_City;
                    //BA_Industry.SelectedValue                   = cst.BA_Industry;
                    //BA_Industry1.SelectedValue                  = cst.BA_Industry1;
                    SetDropDownListValue(BA_Industry, cst.BA_Industry);
                    SetDropDownListValue(BA_Industry1, cst.BA_Industry1);




                    BA_Industry2.Text = cst.BA_Industry2;
                    BA_Industry3.Text = cst.BA_Industry3;
                    SA_Sales_Org.Text = cst.SA_Sales_Org;
                    SA_Sales_Office.Text = cst.SA_Sales_Office;
                    SA_Distribution_Channel.Text = cst.SA_Distribution_Channel;
                    SA_Sales_Employee.Text = cst.SA_Sales_Employee;
                    SA_Sales_Employee_Code.Text = cst.SA_Sales_Employee_Code;
                    SA_Customer_Division_K1.Checked = cst.SA_Customer_Division_K1 == "1";
                    SA_Customer_Division_K2.Checked = cst.SA_Customer_Division_K2 == "1";
                    SA_Customer_Division_K3.Checked = cst.SA_Customer_Division_K3 == "1";

                    SetDropDownListValue(SA_Price_Group_1, cst.SA_Price_Group_1);
                    SetDropDownListValue(SA_Price_Group_2, cst.SA_Price_Group_2);
                    SetDropDownListValue(SA_Price_Group_3, cst.SA_Price_Group_3);

                    SA_Sales_Group_1.Text = cst.SA_Sales_Group_1;
                    SetDropDownListValue(SA_Sales_Group_2, cst.SA_Sales_Group_2);
                    SA_Sales_Group_3.Text = cst.SA_Sales_Group_3;
                    Is_Sales_Null.Text = cst.Is_Sales_Null;
                    Is_K02_Null.Text = cst.Is_K02_Null;
                    IsRSM_Ship.Text = cst.IsRSM_Ship;

                    SA_APO_Customer_Group_APO_K1.Text = cst.SA_APO_Customer_Group_APO_K1;
                    SA_APO_Customer_Group_APO_K2.Text = cst.SA_APO_Customer_Group_APO_K2;
                    SA_APO_Customer_Group_APO_K3.Text = cst.SA_APO_Customer_Group_APO_K3;
                    SA_Partial_Delivery_Per_Item_1.Text = cst.SA_Partial_Delivery_Per_Item_1;
                    SA_Partial_Delivery_Per_Item_2.Text = cst.SA_Partial_Delivery_Per_Item_2;
                    SA_Partial_Delivery_Per_Item_3.Text = cst.SA_Partial_Delivery_Per_Item_3;
                    SA_Max_Partial_Deliveries_1.Text = cst.SA_Max_Partial_Deliveries_1;
                    SA_Max_Partial_Deliveries_2.Text = cst.SA_Max_Partial_Deliveries_2;
                    SA_Max_Partial_Deliveries_3.Text = cst.SA_Max_Partial_Deliveries_3;
                    SA_Switch_Off_Rounding.Checked = cst.SA_Switch_Off_Rounding == "1";
                    SA_Relevant_For_POD.Checked = cst.SA_Relevant_For_POD == "1";
                    SA_Delivery_Priority.Text = cst.SA_Delivery_Priority;
                    SA_Delivery_Priority_1.Text = cst.SA_Delivery_Priority_1;
                    SA_Delivery_Priority_3.Text = cst.SA_Delivery_Priority_3;

                    SA_Shipping_Condition.Text = cst.SA_Shipping_Condition;
                    SA_Rebate.Checked = cst.SA_Rebate == "1";
                    SA_Price_Determin.Checked = cst.SA_Price_Determin == "1";
                    SA_Acct_Assgmt_Group.Text = cst.SA_Acct_Assgmt_Group;
                    SA_Tax_Classification.Text = cst.SA_Tax_Classification;
                    SA_Itcoterms.Text = cst.SA_Itcoterms;
                    SA_Terms_Of_Payment.Text = cst.SA_Terms_Of_Payment;

                    SetDropDownListValue(SA_Attributes_1, cst.SA_Attributes_1);
                    SetDropDownListValue(SA_Attributes_2, cst.SA_Attributes_2);
                    SetDropDownListValue(SA_Attributes_3, cst.SA_Attributes_3);
                    SetDropDownListValue(SA_Attributes_4, cst.SA_Attributes_4);
                    SetDropDownListValue(SA_Account_Type, cst.SA_Account_Type);
                    SetDropDownListValue(SA_Attributes_6, cst.SA_Attributes_6);
                    SetDropDownListValue(SA_No_Trans, cst.SA_No_Trans);

                    BA_County_Code_TextChanged(null, EventArgs.Empty);
                    SetDropDownListValue(SA_Attributes_7, cst.SA_Attributes_7);

                    SA_Attributes_8.Text = cst.SA_Attributes_8;
                    SA_Attributes_9.Text = cst.SA_Attributes_9;
                    SA_Attributes_10.Text = cst.SA_Attributes_10;
                    SA_Customer_Group_2.Text = cst.SA_Customer_Group_2;
                    SA_Customer_Group_3.Text = cst.SA_Customer_Group_3;
                    State_owned_L.Checked = cst.State_owned_L == "1";
                    Foreign_Company_L.Checked = cst.Foreign_Company_L == "1";
                    AN_IG_L.Checked = cst.AN_IG_L == "1";
                    Collective_L.Checked = cst.Collective_L == "1";
                    Private_Enterpris_L.Checked = cst.Private_Enterpris_L == "1";
                    Other_L.Checked = cst.Other_L == "1";
                    SA_Ultimate_Holding_Company.Text = cst.SA_Ultimate_Holding_Company;
                    SA_Paid_In_Capital.Text = cst.SA_Paid_In_Capital;
                    SA_Date_Established_Incorporated.Text = cst.SA_Date_Established_Incorporated;


                    SetDropDownListValue(SA_Invoice_Division, cst.SA_Invoice_Division);
                    SA_Invoice_Division_SelectedIndexChanged(null, null);

                    SetDropDownListValue(SA_Invoice_Type, cst.SA_Invoice_Type);
                    //if (flg)
                    //{
                    SA_Invoice_Type_SelectedIndexChanged(null, null);
                    //}

                    SetDropDownListValue(SA_Attributes5, cst.SA_Attributes5);

                    SA_Existed_Fiscal_Address_Code_1.Text = cst.SA_Existed_Fiscal_Address_Code_1;
                    SA_Invoice_Name.Text = cst.SA_Invoice_Name;

                    SetDropDownListValue(SA_Region, cst.SA_Region);
                    //if (flg)
                    //{
                    SA_Region_SelectedIndexChanged(null, EventArgs.Empty);
                    //}

                    SetDropDownListValue(SA_City, cst.SA_City);


                    SA_City.Text = cst.SA_City;
                    SA_Street5.Text = cst.SA_Street5;
                    SA_City2.Text = cst.SA_City2;
                    SA_District.Text = cst.SA_District;
                    SA_Street.Text = cst.SA_Street;
                    SA_Tel.Text = cst.SA_Tel;
                    SA_Tax_Code.Text = cst.SA_Tax_Code;
                    SA_Bank_Name.Text = cst.SA_Bank_Name;
                    SA_Account.Text = cst.SA_Account;
                    FI_Recon_Account.Text = cst.FI_Recon_Account;
                    FI_Sort_Key.Text = cst.FI_Sort_Key;
                    FI_Cash_Mgmt_Group.Text = cst.FI_Cash_Mgmt_Group;
                    FI_Dunn_Procrdure.Text = cst.FI_Dunn_Procrdure;
                    FI_Payment_Method.Text = cst.FI_Payment_Method;
                    FI_Account_Clerk.Text = cst.FI_Account_Clerk;
                    FI_Customer_User.Text = cst.FI_Customer_User;
                    FI_Act_Clk_Tel_NO.Text = cst.FI_Act_Clk_Tel_NO;
                    FI_Account_Memo.Text = cst.FI_Account_Memo;
                    OT_Estimated_Volume.Text = cst.OT_Estimated_Volume;
                    OT_Estimated_Amount.Text = cst.OT_Estimated_Amount;
                    OT_Currency.Text = cst.OT_Currency;
                    OT_Remarks_1.Text = cst.OT_Remarks_1;
                    OT_Remarks_2.Text = cst.OT_Remarks_2;
                    OT_Remarks_3.Text = cst.OT_Remarks_3;
                    OT_Remarks_4.Text = cst.OT_Remarks_4;
                    OT_Remarks_5.Text = cst.OT_Remarks_5;
                    OT_Remarks_6.Text = cst.OT_Remarks_6;
                    OT_Remarks_7.Text = cst.OT_Remarks_7;
                    //OT_Security_If_any.SelectedValue                     = cst.OT_Security_If_any;
                    SetDropDownListValue(OT_Security_If_any, cst.OT_Security_If_any);

                    OT_Credit_Limit_Proposed.Text = cst.OT_Credit_Limit_Proposed;
                    OT_Credit_Limit_Approved.Text = cst.OT_Credit_Limit_Approved;
                    OT_Credit_Terms_Proposed.Text = cst.OT_Credit_Terms_Proposed;
                    OT_Credit_Terms_Approved.Text = cst.OT_Credit_Terms_Approved;
                    cmd_OT_Comment_By_Sales_Department.Text = cst.cmd_OT_Comment_By_Sales_Department;
                    cmd_OT_Comment_By_Credit_Control_Department.Text = cst.cmd_OT_Comment_By_Credit_Control_Department;
                    NA_Customer_Name.Text = cst.NA_Customer_Name;
                    SetDropDownListValue(NA_Is_Have_Account, cst.NA_Is_Have_Account);
                    NA_Existed_Code.Text = cst.NA_Existed_Code;
                    NA_Customer_Detailed_Add.Text = cst.NA_Customer_Detailed_Add;
                    NA_Fax_No.Text = cst.NA_Fax_No;
                    SetDropDownListValue(NA_Street5, cst.NA_Street5);
                    if (flg)
                    {
                        NA_Street5_SelectedIndexChanged(null, EventArgs.Empty);
                    }

                    NA_City.Text = cst.NA_City;
                    NA_District.Text = cst.NA_District;
                    NA_Street4.Text = cst.NA_Street4;
                    NA_Post_Code.Text = cst.NA_Post_Code;
                    NA_Street.Text = cst.NA_Street;
                    NA_Contact_Preson.Text = cst.NA_Contact_Preson;
                    NA_Tel.Text = cst.NA_Tel;
                    //NA_Region.SelectedValue                   = cst.NA_Region;
                    SetDropDownListValue(NA_Region, cst.NA_Region);
                    NA_Customer_Division_K1.Checked = cst.NA_Customer_Division_K1 == "1";
                    NA_Customer_Division_K2.Checked = cst.NA_Customer_Division_K2 == "1";
                    NA_Customer_Division_K3.Checked = cst.NA_Customer_Division_K3 == "1";
                    NA_Sales_Office.Text = cst.NA_Sales_Office;
                    NA_Sales_Office_1.Text = cst.NA_Sales_Office_1;
                    SAP_Code.Text = cst.SAP_Code;


                    DMO_CheckList.Checked = cst.DMO_CheckList == "1";
                    SetDropDownListValue(DMO_DrpPriority, cst.DMO_DrpPriority);
                    DMO_Arrpvoe_Creation_Number.Text = cst.DMO_Arrpvoe_Creation_Number;
                    DMO_Arrpvoe_Creation_Time.Text = cst.DMO_Arrpvoe_Creation_Time;
                    DMO_Maintain_Creation_Number.Text = cst.DMO_Maintain_Creation_Number;
                    DMO_Maintain_Creation_Time.Text = cst.DMO_Maintain_Creation_Time;
                    DMO_Check_Creation_Number.Text = cst.DMO_Check_Creation_Number;
                    DMO_Check_Creation_Time.Text = cst.DMO_Check_Creation_Time;
                    DMO_Arrpvoe_Revision_Number.Text = cst.DMO_Arrpvoe_Revision_Number;
                    DMO_Arrpvoe_Revision_Time.Text = cst.DMO_Arrpvoe_Revision_Time;
                    DMO_Maintain_Revision_Number.Text = cst.DMO_Maintain_Revision_Number;
                    DMO_Maintain_Revision_Time.Text = cst.DMO_Maintain_Revision_Time;
                    DMO_Check_Revision_Number.Text = cst.DMO_Check_Revision_Number;
                    DMO_Check_Revision_Time.Text = cst.DMO_Check_Revision_Time;


                }
                #endregion

                #region 审批项初始化
                switch (TaskAPI.Step)
                {
                    case "DMO Approve":
                    case "DMO Maintain":
                    case "DMO Check":

                    case "DMO Change Z1":
                        Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                        Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                        break;
                    case "CA Check":
                    case "RSM":
                    case "RPM":
                    case "PC Manager":
                    case "Ship to Mgr":
                    case "SM/PSM/SO":
                        Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                        Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                        break;
                    case "AR":
                    case "AR Check":
                    case "CA Refund":
                    case "Issue Termination Notice":
                        Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                        Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                        break;
                    case "CCC":
                    case "MC":
                    case "Store Operation":
                    case "Store Operation Check":
                    case "CA Confirm":
                        Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                        break;
                }
                #endregion
            }
            #endregion


            SetDefaultValue();
            InitTabs();

            #region 设置控件禁启用

            SetEnable(flg, Actions, DrpPriority, Keys, BA_Customer_Name_In_ZH, SA_Invoice_Division, BA_Business_License_No, BA_SoldTo_Relation, BA_Existed_Sold_To_Code, BA_Block_Existed_Code, BA_Hierarchy_1, BA_Hierarchy_2, BA_Contact_Person, BA_Contact_Person_Mobile_Phone, BA_Contact_Person_SMS, BA_Responsible_Man, BA_Responsible_Mobile_Phone, BA_Responsible_Man_SMS, BA_Sales_Employee_K1, BA_Sales_Employee_K1_Mobile_Phone, BA_Sales_Employee_K1_SMS, BA_Sales_Employee_K1_Employee_Code, BA_Sales_Employee_K2, BA_Sales_Employee_K2_Mobile_Phone, BA_Sales_Employee_K2_SMS, BA_Sales_Employee_K2_Employee_Code, BA_Sales_Employee_K3, BA_Sales_Employee_K3_Mobile_Phone, BA_Sales_Employee_K3_SMS, BA_Sales_Employee_K3_Employee_Code, BA_Customer_Name_In_EN, BA_Address_In_EN, BA_Existed_Sold_To_Code_Street5, BA_Existed_Sold_To_Code_City, BA_Existed_Sold_To_Code_District, BA_Existed_Sold_To_Code_Street_4, BA_Existed_Sold_To_Code_Post_Code, BA_Existed_Sold_To_Code_Street, BA_Existed_Sold_To_Code_Contact_Preson, BA_Existed_Sold_To_Code_Tel, BA_Existed_Sold_To_Code_Email, BA_Existed_Bill_To_Code, BA_Existed_Bill_To_Code_Street5, BA_Existed_Bill_To_Code_City, BA_Existed_Bill_To_Code_District, BA_Existed_Bill_To_Code_Street_4, BA_Existed_Bill_To_Code_Post_Code, BA_Existed_Bill_To_Code_Street, BA_Existed_Bill_To_Code_Contact_Preson, BA_Existed_Bill_To_Code_Tel, BA_Existed_Bill_To_Code_Email, BA_Existed_Dunn_Recipient_Code, BA_Existed_Dunn_Recipient_Street5, BA_Existed_Dunn_Recipient_City, BA_Existed_Dunn_Recipient_District, BA_Existed_Dunn_Recipient_Street_4, BA_Existed_Dunn_Recipient_Post_Code, BA_Existed_Dunn_Recipient_Street, BA_Existed_Dunn_Recipient_Contact_Preson, BA_Existed_Dunn_Recipient_Tel, BA_Existed_Dunn_Recipient_Email, BA_IsNeedDunn, BA_Sales_Office, BA_Region, BA_City_Code, BA_Industry, BA_Industry1, SA_Customer_Division_K1, SA_Customer_Division_K2, SA_Customer_Division_K3, SA_Price_Group_1, SA_Sales_Group_1, SA_Sales_Group_2, SA_Sales_Group_3, SA_Price_Group_2, SA_Price_Group_3, SA_Attributes_1, SA_Attributes_2, SA_Attributes_7, SA_Attributes_3, SA_Attributes_4, SA_Account_Type, SA_Attributes_6, SA_No_Trans, State_owned_L, Foreign_Company_L, AN_IG_L, Collective_L, Private_Enterpris_L, Other_L, SA_Ultimate_Holding_Company, SA_Paid_In_Capital, SA_Date_Established_Incorporated, SA_Invoice_Type, SA_Attributes5, SA_Existed_Fiscal_Address_Code_1, SA_Invoice_Name, SA_Region, SA_City, SA_Street5, SA_City2, SA_District, SA_Street, SA_Tel, SA_Tax_Code, SA_Bank_Name, SA_Account, FI_Customer_User, FI_Act_Clk_Tel_NO, FI_Account_Memo, OT_Estimated_Volume, OT_Estimated_Amount, OT_Remarks_1, OT_Remarks_2, OT_Remarks_3, OT_Remarks_4, OT_Remarks_5, OT_Remarks_6, OT_Remarks_7, OT_Security_If_any, OT_Credit_Limit_Proposed, OT_Credit_Limit_Approved, OT_Credit_Terms_Proposed, OT_Credit_Terms_Approved, cmd_OT_Comment_By_Sales_Department, cmd_OT_Comment_By_Credit_Control_Department, NA_Customer_Name, NA_Is_Have_Account, NA_Existed_Code, NA_Customer_Detailed_Add, NA_Fax_No, NA_Street5, NA_City, NA_District, NA_Street4, NA_Post_Code, NA_Street, NA_Contact_Preson, NA_Tel, NA_Region, NA_Customer_Division_K1, NA_Customer_Division_K2, NA_Customer_Division_K3);
            SetEnable(TaskAPI.Step == "DMO Maintain" && TaskAPI.IsAllowSubmit, SAP_Code);

            SetVisible(TaskAPI.IsAllowSubmit, Send, Split, Save);
            Save.Visible = flg;
            SetEnable(TaskAPI.Step == "DMO Approve", DMO_CheckList);
            SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority, DMO_Arrpvoe_Creation_Number, DMO_Arrpvoe_Creation_Time, DMO_Maintain_Creation_Number, DMO_Maintain_Creation_Time, DMO_Check_Creation_Number, DMO_Check_Creation_Time, DMO_Arrpvoe_Revision_Number, DMO_Arrpvoe_Revision_Time, DMO_Maintain_Revision_Number, DMO_Maintain_Revision_Time, DMO_Check_Revision_Number, DMO_Check_Revision_Time);
            SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO, P_Approve);
            Assessment1.Enable = TaskAPI.IsAllowSubmit;

            //if (TaskAPI.Step == "DMO Approve")
            //{
            //    SetForeColor(Color.Blue, DMO_DrpPriority_L);
            //}
            if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue == "1")
            {
                SetForeColor(Color.Blue, DMO_Arrpvoe_Creation_L);
            }
            if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue == "1")
            {
                SetForeColor(Color.Blue, DMO_Maintain_Creation_L);
            }
            if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue == "1")
            {
                SetForeColor(Color.Blue, DMO_Check_Creation_L);
            }
            if (TaskAPI.Step == "DMO Approve" & Actions.SelectedValue != "1")
            {
                SetForeColor(Color.Blue, DMO_Arrpvoe_Revision_L);
            }
            if (TaskAPI.Step == "DMO Maintain" & Actions.SelectedValue != "1")
            {
                SetForeColor(Color.Blue, DMO_Maintain_Revision_L);
            }
            if (TaskAPI.Step == "DMO Check" & Actions.SelectedValue != "1")
            {
                SetForeColor(Color.Blue, DMO_Check_Revision_L);
            }
            //Attachment1.AllowDelete = flg;
            //Attachment1.AllowUpload = flg;
            #endregion

            #region 魏君添加 修改textbox的enalbe属性
            if (!flg || !TaskAPI.IsAllowSubmit)
            {
                foreach (Control cr in P1.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in P1.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }

                foreach (Control cr in P3.Controls)
                {
                    if (cr is TextBox)
                    {
                        TextBox tb = (TextBox)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ReadOnly = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                foreach (Control cr in P3.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                }
                //this.Actions.Enabled = true;
            }
            #endregion
            if (Keys.Items[1].Selected && !Keys.Items[0].Selected)
            {
                ShipTo1.Add.Visible = false;
            }

            //BA_County_Code_TextChanged(null, e);
            //SetDropDownListValue(SA_Attributes_7, cst.SA_Attributes_7);
        }

        #endregion

        #region Hierarchy1带Industry code2
        protected void BA_Hierarchy_1_TextChanged(object sender, EventArgs e)
        {
            if (BA_Hierarchy_1.Text != "")
            {
                m_Hierarchy1 mi2 = (m_Hierarchy1.hierarchy1 == (sender as TextBox).Text).ListFirst<m_Hierarchy1>();
                if (mi2 != null)
                {
                    BA_Industry2.Text = mi2.Industry2;
                }

                else
                {
                    BA_Industry2.Text = "";
                }
            }
            else
            {
                BA_Industry2.Text = "";
            }

        }
        #endregion

    }

    public interface ITempSave
    {
        void SaveData(bool submit);

        bool IsDraftExisted { get; }

        void LoadData(string action);
    }

    public enum ProcessDataState
    {
        Normal = 1,

        Draft = -1
    }

}
